首页 > 解决方案 > 将空共享字符串写入单元格 openxml

问题描述

但是,在代码运行后,我正在尝试将共享字符串写入单元格。我发现超链接单元格是空的文本。但是超链接在那里。

string[] words = data.Split('!');

string cellReference = string.Format("{0}{1}", columnText, rowIndex);
string uniqueID = "hyperlink" + linkIndex.ToString();
Hyperlink hyperlink1 = new Hyperlink() { Reference = cellReference, Id = uniqueID };
hyperlinks1.Append(hyperlink1);
wsPart.Worksheet.Save();
wsPart.AddHyperlinkRelationship(new System.Uri(attachmentDownloadURL + "?id=" + words[0].ToString(), System.UriKind.Absolute), true, uniqueID);

// add hyperlink text to shared string table
shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new DocumentFormat.OpenXml.Spreadsheet.Text(words[1])));
shareStringPart.SharedStringTable.Save();

cell.CellReference = cellReference;

cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
cell.CellValue = new CellValue(linkIndex.ToString());
cell.StyleIndex = styleHyperlink;
linkIndex++;
}

我的代码有什么问题吗?

标签: c#xmlexcelopenxml

解决方案


推荐阅读