我添加了一行示例代码,这就是我想要得到的结果。请帮助如果任何人有想法如何实现这一点,只需要使用openXml库。
Hyperlink hyperlink = new Hyperlink()
{
Reference = "A" + indexer,
Location = "Unique" + (indexer - 1) + "!A1",
Display = "Unique" + indexer,
};
attributes.Add(new OpenXmlAttribute("t", null, "inlineStr"));
var cell = new Cell() { CellReference = hyperlink.Display };
//cell.InnerText = "dfd";
writer.WriteStartElement(cell, attributes);
//writer.WriteStartElement(hyperlink, attributes);
//writer.WriteString("fdf");
//writer.WriteElement(new InlineString(new Text("dfdfs")));
writer.WriteStartElement(new InlineString(hyperlink));
writer.WriteEndElement();
发布于 2019-09-13 17:42:32
下面的示例代码使用Open XML在Excel文件中添加超链接,并在单击超链接时打开另一个选项卡:
if (attributes == null)
{
attributes = new List<OpenXmlAttribute>();
}
//Here I created the hyperlink
string xx = @"HYPERLINK(""[KillFile2.xlsx]Sheet1!A10"", ""Go to
Sheet1 > A10"")";
attributes.Add(new OpenXmlAttribute("t", null, "inlineStr"));
writer.WriteStartElement(new Cell(), attributes);
//Here hyperlink added to cell formula
writer.WriteElement(new CellFormula(xx));
writer.WriteEndElement();
https://stackoverflow.com/questions/57907150
复制相似问题