15
我想寫一些代碼來生成一個Excel電子表格,我不知道CellValues.InlineString和CellValues.String之間的區別插入文本的單元格。OpenXML中的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);
}
請哪裏是你所引用的文件的鏈接? –
我用鏈接更新了答案,以便下載打開xml規範的pdf。您可以在那裏搜索或參考此示例http://msdn.microsoft.com/en-us/library/documentformat.openxml.spreadsheet.cell%28v=office.14%29.aspx – amurra