我有一段代码(如下图),可以得到在Excel中特定细胞的文字,但我不知道如何修改这个文本以更改单元格文本。
public static void UpdateTextCell(string docName, string text, uint rowIndex,
string columnName, string sheetName)
{
// Open the document for editing.
using (SpreadsheetDocument spreadSheet = SpreadsheetDocument
.Open(docName, true))
{
WorksheetPart worksheetPart = GetWorksheetPartByName(spreadSheet,
sheetName);
if (worksheetPart != null)
{
SharedStringTablePart sharedstringtablepart=spreadSheet.WorkbookPart
.GetPartsOfType<SharedStringTablePart>().First();
SharedStringTable sharedStringTable = sharedstringtablepart
.SharedStringTable;
Cell cell = GetCell(worksheetPart.Worksheet, columnName, rowIndex);
if (cell.DataType.Value == CellValues.SharedString)
{
var value = cell.InnerText;
value = sharedStringTable.ElementAt(int.Parse(value)).InnerText;
sharedStringTable.ElementAt(int.Parse(value)).InnerXml
.Replace("value", "Modified");
}
// Save the worksheet.
worksheetPart.Worksheet.Save();
}
}
}
由于sharedStringTable.ElementAt(int.Parse(value)).InnerText
为只读,我试图修改使用文本字符串sharedStringTable.ElementAt(int.Parse(value)).InnerXml.Replace("value", "Modified");
但是这也不行。
你知道我失踪?