0
我是Openxml中的新成員。我正在嘗試使用openxml創建一個xlsx文件。我想將不同的字體和顏色應用於Excel文件中不同單元格的文本。我用這個創建一個xlsx文件,但不能做字體和顏色部分。如何在Excel文件的單元格中使用openxml在文本中應用字體和顏色
SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create("E:\\Word9.xlsx", SpreadsheetDocumentType.Workbook);
WorkbookPart workbookpart = spreadsheetDocument.AddWorkbookPart();
workbookpart.Workbook = new Workbook();
WorksheetPart worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet(new SheetData());
Sheets sheets = spreadsheetDocument.WorkbookPart.Workbook.AppendChild<Sheets>(new Sheets());
int i = 1;
while (i <= 5)
{
Sheet sheet = new Sheet() { Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), SheetId = (UInt32)i, Name = "mySheet" + i.ToString() };
for (int ii = 1; ii <= 5; ii++)
{
Row row1 = new Row();
sheets.AppendChild(row1);
Cell cll = new Cell(new InlineString(new DocumentFormat.OpenXml.Spreadsheet.Text("qqqqqq"))) { DataType = CellValues.InlineString };
row1.AppendChild(cll);
}
sheets.Append(sheet);
i++;
}
workbookpart.Workbook.Save();
有沒有人知道如何將字體和顏色應用到不同的單元格?