【发布时间】:2011-06-24 13:52:40
【问题描述】:
我正在尝试编写一些代码来生成 Excel 电子表格,但我不确定在 CellValues.InlineString 和 CellValues.String 之间插入文本的区别细胞。
我可以用这个吗:
private void UpdateCellTextValue(Cell cell,string cellValue)
{
InlineString inlineString = new InlineString();
Text cellValueText = new Text { Text = cellValue };
inlineString.AppendChild(cellValueText);
cell.DataType = CellValues.InlineString;
cell.AppendChild(inlineString);
}
这个
private void UpdateCellTextValue(Cell cell, string cellValue)
{
cell.CellValue = new CellValue(cellValue);
cell.DataType = new EnumValue<CellValues>(CellValues.String);
}
或者只是这个(InsertSharedStringItem 返回新插入的共享字符串项的 Id)
private void SetCellSharedTextValue(Cell cell,string cellValue)
{
int stringId = InsertSharedStringItem(cellValue);
cell.CellValue = new CellValue(stringId.ToString());
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
}
【问题讨论】:
标签: c# openxml openxml-sdk