Open XML SDK 2.0 - how to update a cell in a spreadsheet?

后端 未结 6 1877
我寻月下人不归
我寻月下人不归 2020-11-30 20:50

I want to update a cell in a spreadsheet that is used by a chart, using the Open XML SDK 2.0 (CTP). All the code samples I have found insert new cells. I am struggling with

6条回答
  •  春和景丽
    2020-11-30 21:26

    var sheetData = new SheetData();
    var row = UpdateCell("A","Hello World", 5);
    sheetData.Append(row);
    worksheet.Append(sheetData);
    
    private static Row UpdateCell(string columnName, string value, int rowIndex)
    {
           Row row = new Row { RowIndex = (uint)rowIndex };
           Cell  c1 = new TextCell(columnName, value, rowIndex);
           row.Append(c1);
           return row;            
    }
    
    
    public class TextCell : Cell
    {
        public TextCell(string header, string text, int index)
        {
            this.DataType = CellValues.InlineString;
            this.CellReference = header + index;
            //Add text to the text cell.
            this.InlineString = new InlineString { Text = new Text { Text = text } };
        }
    }
    

提交回复
热议问题