private void Export() { GC.Collect(); Application excelApp = new ApplicationClass(); excelApp.Visible = false; List <Worksheet> excelSheetList = new List <Worksheet>(); Workbook excelBook = excelApp.Workbooks.Add(Type.Missing); if (Session["AdvanceSearchContractResult"] != null) { Worksheet excelSheet3 = (Worksheet)excelBook.Sheets.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing); excelSheetList.Add(excelSheet3); excelSheet3.Name = "员工合同高级查询"; ExportToExcel(excelSheet3); } ExcelExportUtility.RemoveBlankWorkSheet(excelBook); object nothing = Type.Missing; object fileFormat = XlFileFormat.xlExcel8; object file = Server.MapPath(".") + "\\员工合同高级查询.xls"; if (File.Exists(file.ToString())) { File.Delete(file.ToString()); } excelBook.SaveAs(file, fileFormat, nothing, nothing, nothing, nothing, XlSaveAsAccessMode.xlNoChange, nothing, nothing, nothing, nothing, nothing); excelBook.Close(false, null, null); ExcelExportUtility.ReleaseComObject(excelApp, excelBook, excelSheetList); ExcelExportUtility.KillProcess(excelApp, "Excel"); ExcelExportUtility.OutputExcel(Server, Response, "员工合同高级查询"); }
private void Export() { GC.Collect(); Application excelApp = new ApplicationClass(); excelApp.Visible = false; List <Worksheet> excelSheetList = new List <Worksheet>(); Workbook excelBook = excelApp.Workbooks.Add(Type.Missing); Worksheet excelSheet3 = (Worksheet)excelBook.Sheets.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing); excelSheetList.Add(excelSheet3); excelSheet3.Name = "工作计划"; ExportToExcel(excelSheet3); ExcelExportUtility.RemoveBlankWorkSheet(excelBook); object nothing = Type.Missing; object fileFormat = XlFileFormat.xlExcel8; string path = ConfigurationManager.AppSettings["EmployeeExportLocation"]; if (!Directory.Exists(path)) //判断是否存在 { Directory.CreateDirectory(path); //创建新路径 } object file = path + "\\工作计划表" + DateTime.Now.ToBinary() + ".xls"; if (File.Exists(file.ToString())) { File.Delete(file.ToString()); } excelBook.SaveAs(file, fileFormat, nothing, nothing, nothing, nothing, XlSaveAsAccessMode.xlNoChange, nothing, nothing, nothing, nothing, nothing); excelBook.Close(false, null, null); ExcelExportUtility.ReleaseComObject(excelApp, excelBook, excelSheetList); ExcelExportUtility.KillProcess(excelApp, "Excel"); ExcelExportUtility.OutputExcel(file.ToString(), _Context.Server, _Context.Response); }