LinqToExcel获取超链接值

我正在使用LinqToExcel来读取一个Excel文件。 一切工作正常,但它的单元格的内容是一个超链接,我只得到超链接文本。 我想获得它的url/电子邮件。

try { // Connection to the DB iRentDB db = new iRentDB(); // Get excel file and work sheet string pathToExcelFile = @"Members_Export_1500068180.xls"; string sheetName = "Members_Export_1500068180"; var excelFile = new LinqToExcel.ExcelQueryFactory(pathToExcelFile); // Select all rows from Excel var rows = from c in excelFile.WorksheetNoHeader(sheetName) select c; foreach (var row in rows) { // Get and validate the email var email = row[8].Value.ToString(); } }catch (Exception any) { Console.Write(any.ToString()); } 

我正在阅读的单元格是一个超链接。 单元格内容名称为“电子邮件”,超链接值为test@test.com。 在我的C#代码中,variablesemail =“Email”。 我怎样才能设置variables电子邮件的超链接值(“test@test.com”)?

谢谢

以编程方式将内容添加到工作表时,Excel应用程序不会自动编辑单元格来格式化并添加超链接(就像手动input单元格一样)。

我不确定LinqToExcel是否有添加超链接的选项,但您可以考虑使用EPPlus,这里是链接: 如何使用EPPlus在单元格内创build链接 。

使用EPPlus,您几乎可以用excel做任何事情,就像Microsoft.Office.Interop.Excel,主要用于桌面应用程序(Interop样本)一样:

  Excel.Worksheet ws; ws.Hyperlinks.Add(ws.Cells[5,8], "test@test.com"); ws.Hyperlinks.Add(ws.Range["B4"], "test2@anothertest.com"); 

我知道这不是你正在寻找的答案,但我的观点是超链接不会自动添加。