单元格没有显示任何文字 [英] the cell did not display any text

查看:99
本文介绍了单元格没有显示任何文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

      我试图添加超链接和显示文本到单元格。我发现超链接被写入单元格,但链接没有显示文本。我确实尝试添加文本,但似乎我的代码有一些问题。以下
是我的代码。请帮忙。

       I am trying to add hyperlink and display text to a cell. I found that the hyperlink is written to the cell but there is no display text for the link. I do try to add the text but it seems my code is having some problem. The follows is my code. Please help.

{
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++;
}

hon123456

hon123456

推荐答案

您好hon123456,

Hello hon123456,

我没有看到您将单元格保存到工作表部分的位置。你有没有做过?

I did not see where you save the cell to the worksheet part. Have you ever done it?

如果没有,你需要先将单元格插入工作表部分。

If not, you need insert the cell to the worksheet part first.

如果你做了,我会建议您使用Open XML SDK Tools来检查单词[1]的字符串是否确实首先插入到SharedStringTablePart中。然后,我建议你使用单词[1]循环遍历SharedStringTablePart,返回单词[1]的
索引,而不是硬编码为其分配链接索引。

If you have done, I would suggest you use Open XML SDK Tools to check if the string of words[1] is indeed inserted in to the SharedStringTablePart first. And then, I would suggest you use the words[1] to loop through the SharedStringTablePart to return an index of the words[1] instead of hardcoding to assign a linkindex for it.

最诚挚的问候,

Terry


这篇关于单元格没有显示任何文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆