1
我使用Office OpenXML來使用Windows服務生成XML文件。代碼工作正常,並生成excel文件。但是現在我想爲行和單元添加一些樣式。我怎樣才能做到這一點? 我使用的代碼是:將樣式應用於使用office open xml生成的excel文件C#
if (thermoCoupleList.Count > 0)
{
FileInfo newFile = new FileInfo(filePath);
using (ExcelPackage xlPackage = new ExcelPackage(newFile))
{
ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets.Add("ThermoCouples");
// write some titles into row 1
worksheet.Cell(1, 1).Value = "Thermocouple ID";
worksheet.Cell(1, 2).Value = "Calibration Done Date";
worksheet.Cell(1, 3).Value = "Calibration Due Date";
worksheet.Cell(1, 4).Value = "Company";
int col, row = 1;
foreach (Thermocouples tc1 in thermoCoupleList)
{
col = 1;
row = row + 1;
worksheet.Cell(row, col++).Value = Convert.ToString(tc1.ThermocoupleIdentification);
worksheet.Cell(row, col++).Value = tc1.CalibrationDoneDate;
worksheet.Cell(row, col++).Value = tc1.CalibrationDueDate;
worksheet.Cell(row, col++).Value = tc1.Company;
}
xlPackage.Save();
}
}
我如何在Office OpenXML的實現造型?
在哪裏定義此AddStyles函數?然後在哪裏使用它? – Priya
你可以在你想要的地方做到這一點。例如,我打開文檔進行修改時調用此函數。在此之後'使用(SpreadsheetDocument文檔= SpreadsheetDocument.Open(FilePath,true)) var styleSheet = document.WorkbookPart.WorkbookStylesPart.Stylesheet;'您應該在類中修改excel文檔 – Disappointed
Spreadsheet包含哪些名稱空間? – Priya