使用.net core
多年之后,我才刚开始编写我的第一个.net framework
控制台应用程序。
在框架中,我编写了许多写给excel文档的应用程序,并且基本上将部分代码粘贴到了核心应用程序中。
private static void createExcelDocument(DataTable dt)
{
//creates an instance of excel
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
xlApp = new Excel.Application();
xlApp.Visible = false;
xlApp.DisplayAlerts = false;
object misValue = System.Reflection.Missing.Value;
xlWorkBook = xlApp.Workbooks.Add(misValue);
Excel.Worksheet xlWorksheet;
xlWorksheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlWorksheet.Name = DateTime.Today.ToString("yyyyMMdd");
string[] columnHeaders = { "Work Order", "Parent WO", "Description", "Location", "Asset", "Status",
"Scheduled Start", "Scheduled Finish", "Planning Group", "Priority", "Availability?",
"Work Type", "Safety Related Flag", "Parent Location", "Asset Description", "Overdue" };
int x = 0;
foreach(string ch in columnHeaders)
{
xlWorksheet.Cells[1, x] = ch;
x++;
}
//saves the excel document
xlWorkBook.SaveAs(folderPath + filename);
xlWorkBook.Close(true, misValue, misValue);
cleanUp(xlApp, xlWorkBook, xlWorksheet);
}
上面的代码确实更改了工作表选项卡的名称,但没有写在列标题中。我想念什么?