我一直在尝试从我正在读入的文件上的单元格获取超链接。我遇到的问题是我无法提取整个地址,不确定语法是什么或遗漏了什么。我正在使用 C# 和 MS 互操作,因为由于公司政策不能使用第 3 方 pkgs。已尝试以下代码作为测试,它仅从指定单元格中提取部分嵌入地址。
我已经尝试过一些类似的事情。 Console.Write(excelRange.Cells[3, 2].hyperlinks(1).Address);但它不会返回整个地址,仅返回部分地址 http://somewebsite.com/app
当整个地址格式为:http://somewebsite.com/app#/morethings-1/somemorethings/information-743028
任何帮助将不胜感激。谢谢你
using Excel= Microsoft.Office.Interop.Excel;
var excel = new Excel.Application();
Excel.Workbook workbook = excel.Workbooks.Open("path_to_file");
var worksheet = (Excel.Worksheet)workbook.Sheets["Sheet1"];
string cellValue = (worksheet.Cells[2, 2] as Excel.Range).Value2.ToString();
Console.Write(cellValue);
上面给出了完整的值,因为我们从单元格获取值而不是超链接的地址。我认为构建超链接时地址有问题。地址与单元格中的文本不同。
地址 => http://somewebsite.com/app
CellValue => http://somewebsite.com/app #/morethings-1/somemorethings/information-743028