amu*_*rra 0 openxml spreadsheetml openxml-sdk
我似乎无法找到有关如何使用Open XML SDK 2.0在Excel 2007中向单元格添加超链接的任何文档或代码示例.我使用以下代码,但是我缺少一个步骤吗?
WorksheetPart workSheetPart = ExcelUtilities.GetWorkSheetPart(mWorkBookPart, "Program");
workSheetPart.AddHyperlinkRelationship(new Uri("http://www.google.com", UriKind.Absolute), true);
workSheetPart.Worksheet.Save();
mWorkBookPart.Workbook.Save();
Run Code Online (Sandbox Code Playgroud)
然后当我尝试打开Excel文档时,它说文件已损坏,因为无法找到超链接的关系ID.您如何设置或创建关系ID?
小智 8
另一种可能性(我使用过)是使用Excel 的HYPERLINK公式.我需要在每个单元格中创建单独的超链接,但单元格必须显示不同的文本,(我必须在单元格中显示跟踪编号,但是每个跟踪编号都有一个超链接到运营商的网站,并且必须处理多个运营商).
一旦我实例化了一个单独的单元格,就会以这种方式将公式应用于每个单元格(毫无疑问,有很多方法):
// ...
Cell cell1 = new Cell(){ CellReference = "A1", StyleIndex = (UInt32Value)1U, DataType = CellValues.InlineString };
CellValue cellValue1 = new CellValue();
CellFormula cellFormula1 = new CellFormula() { Space = SpaceProcessingModeValues.Preserve };
cellFormula1.Text = @"HYPERLINK(""http://www.theclash.com"", ""Radio Clash"")";
cellValue1.Text = "Radio Clash";
cell1.Append(cellFormula1);
cell1.Append(cellValue1);
// append cell, etc.
Run Code Online (Sandbox Code Playgroud)
通过这种方式,我能够为每个单元格创建单独的超链接和文本.顺便说一下,除非您引用带有蓝色字体的样式,否则链接将以默认字体颜色显示.
希望这可以帮助.
| 归档时间: |
|
| 查看次数: |
10063 次 |
| 最近记录: |