using (SpreadsheetDocument myDoc = SpreadsheetDocument.Open(stream, false)) { WorkbookPart workbookPart = myDoc.WorkbookPart; foreach (var worksheetPart in workbookPart.WorksheetParts) { //所有超链接hyperlink数据表 var hyperlinks = worksheetPart.RootElement.Descendants<Hyperlinks>().First().Cast<Hyperlink>(); var sheet = worksheetPart.Worksheet.Elements<SheetData>().First(); foreach (Row r in sheet.Elements<Row>()) { var cell = (Cell)r.ElementAtOrDefault(1); //举例获取一个单元格 cell = (Cell)r.ElementAt(1); //通过单元格列头信息获取超链接 var hyperlink = hyperlinks.SingleOrDefault(i => i.Reference.Value == cell.CellReference.Value); if (hyperlink != null) { var hyperlinksRelation = worksheetPart.HyperlinkRelationships.SingleOrDefault(i => i.Id == hyperlink.Id); if (hyperlinksRelation != null) { //这是最终我们需要的超链接 var url = hyperlinksRelation.Uri.ToString(); } } } } }
使用OPEN XML SDK 读取EXCEL中的超链接Hyperlink,布布扣,bubuko.com
使用OPEN XML SDK 读取EXCEL中的超链接Hyperlink
原文地址:http://blog.csdn.net/leewhoee/article/details/26760765