/// <summary> /// 写Excel文件 /// </summary> /// <param name="excelFile"></param> /// <param name="data"></param> /// <param name="sheetName"></param> public static void ExportToExcel(string excelFile, DataTable data, string sheetName) { try { data.TableName = sheetName; ExcelBuilder eb = new ExcelBuilder(); eb.WorkBookObj = new XSSFWorkbook(); eb.initStyles(); eb.writeTheSheet(data); //处理研究目标和研究内容列表的宽度问题 ISheet sheetObj = eb.WorkBookObj.GetSheetAt(0); sheetObj.SetColumnWidth(0, 60 * 256 + 200); sheetObj.SetColumnWidth(3, 60 * 256 + 200); sheetObj.SetColumnWidth(4, 60 * 256 + 200); eb.saveWorkbookToFile(excelFile); MessageBox.Show("导出数据成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); GC.Collect(); Process.Start(excelFile); } catch (Exception ex) { MessageBox.Show("导出Excel失败!Ex:" + ex.ToString()); } }
/// <summary> /// 写Excel文件 /// </summary> /// <param name="excelFile"></param> /// <param name="data"></param> /// <param name="sheetName"></param> public static void ExportToExcel(string excelFile, DataTable data, string sheetName) { try { data.TableName = sheetName; ExcelBuilder eb = new ExcelBuilder(); eb.WorkBookObj = new XSSFWorkbook(); eb.initStyles(); eb.writeTheSheet(data); eb.saveWorkbookToFile(excelFile); MessageBox.Show("导出数据成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); GC.Collect(); Process.Start(excelFile); } catch (Exception ex) { MessageBox.Show("导出Excel失败!Ex:" + ex.ToString()); } }