相关疑难解决方法(0)

OpenXML中的CellValues.InlineString和CellValues.String有什么区别?

我正在尝试编写一些代码来生成Excel电子表格,我不确定CellValues.InlineStringCellValues.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)

c# openxml openxml-sdk

16
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

openxml ×1

openxml-sdk ×1