/// <summary> /// 创建一个EXCEL文件 /// </summary> /// <param name="ExcelFilePath"></param> public static void CreateExcel(string ExcelFilePath) { Excel.Application EApp = new Excel.Application(); //Excel应用程序 Excel.Workbook EWBook; //Excel文档 Excel.Worksheet WSheet; object nothing = Missing.Value; EWBook = EApp.Workbooks.Add(nothing); WSheet = EWBook.Worksheets[1] as Excel.Worksheet; //WSheet.SaveAs(ExcelFilePath, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); WSheet.SaveAs(ExcelFilePath, 52, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); EWBook.Save(); EWBook.Close(false, Type.Missing, Type.Missing); EApp.Quit(); KillSpecialExcel(EApp); }
protected void CreateSheet(Workbook xlWorkBook) { WSheet = (Worksheet)xlWorkBook.Worksheets.Add(); // change sheet name WSheet.Name = SheetName; // create header int colIndex = 1; foreach (string s in Headers) { WSheet.Cells[1, colIndex++] = s; } Range headerRange = WSheet.get_Range((Range)WSheet.Cells[1, 1], (Range)WSheet.Cells[1, Headers.Length]); headerRange.Font.Bold = true; headerRange.Columns.AutoFit(); RowIndex++; }