如何加入几个细胞?

时间:2019-07-01 09:38:23

标签: c# excel openxml openxml-sdk

我有一个带有文字的单元格。其中一些单元格用粗体字表示。这意味着我应该将几个单元格保存为一个字体。

例如:enter image description here

我使用了OpenXML,我做了以下事情:

using(SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(@"C:\Users\anton.belenik\source\repos\openXML\openXML\SPG BY Glossary Anton.xlsx", true)) {
    string cellValue;
    int rowNumber = 0;
    WorkbookPart workbookPart = spreadsheetDocument.WorkbookPart;
    Sheet workSheet = workbookPart.Workbook.Descendants<Sheet>().Where(p => p.Name.Value.Equals("Sheet1")).FirstOrDefault();
    WorksheetPart worksheetPart = (WorksheetPart)(workbookPart.GetPartById(workSheet.Id));
    SheetData sheetData = worksheetPart.Worksheet.Elements<SheetData>().First();
    foreach(Row r in sheetData.Elements<Row>()) {
        rowNumber++;
        foreach(Cell c in r.Elements<Cell>()) {
            cellValue = GetCellValue(workbookPart, "Sheet1", c.CellReference);
        }
    }

0 个答案:

没有答案