我正在尝试编写一些代码来生成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);
}
Run Code Online (Sandbox Code Playgroud)
这个
private void UpdateCellTextValue(Cell cell, string cellValue)
{
cell.CellValue = new CellValue(cellValue);
cell.DataType = new EnumValue<CellValues>(CellValues.String);
}
Run Code Online (Sandbox Code Playgroud)
或者只是这个(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);
}
Run Code Online (Sandbox Code Playgroud)