gpt4 book ai didi

c# - 将多个单元格添加到单个行

转载 作者:行者123 更新时间:2023-11-30 15:05:23 25 4
gpt4 key购买 nike

我是新手,当我尝试向一行中添加多个单元格时,它说存在不可读的内容。这是我的。

SpreadsheetDocument ssDoc = SpreadsheetDocument.Create(saveFile, SpreadsheetDocumentType.Workbook);

// Add a WorkbookPart to the document
WorkbookPart workbookPart = ssDoc.AddWorkbookPart();
workbookPart.Workbook = new Workbook();
// Add a WorksheetPart to theWorkbookPart
WorksheetPart worksheetPart = workbookPart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet(new SheetData());

Sheets sheets = ssDoc.WorkbookPart.Workbook.AppendChild<Sheets>(new Sheets());

Sheet sheet = new Sheet()
{ Id = ssDoc.WorkbookPart.GetIdOfPart(worksheetPart),
SheetId = 1, Name = "Sheet1"
};

sheets.Append(sheet);
Worksheet worksheet = new Worksheet();
SheetData sheetData = new SheetData();
Row row = new Row();

Cell cell = new Cell()
{
CellReference = "A1",
DataType = CellValues.String,
CellValue = new CellValue("Cell1")
};

Cell cell2 = new Cell()
{
CellReference = "A2",
DataType = CellValues.String,
CellValue = new CellValue("Cell2")
};
row.Append(cell);
row.Append(cell2);

sheetData.Append(row);
worksheet.Append(sheetData);
worksheetPart.Worksheet = worksheet;
// Close the document.
ssDoc.Close();

如果我删除第二个单元格,它会按预期工作。

最佳答案

单元格引用应该是“B1”而不是“A2”

        SpreadSheet.Cell cell = new SpreadSheet.Cell()
{
CellReference = "A1",
DataType = SpreadSheet.CellValues.String,
CellValue = new SpreadSheet.CellValue("Cell1")
};

SpreadSheet.Cell cell2 = new SpreadSheet.Cell()
{
CellReference = "B1",
DataType = SpreadSheet.CellValues.String,
CellValue = new SpreadSheet.CellValue("Cell2")
};

关于c# - 将多个单元格添加到单个行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9117013/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com