/// <summary> /// 导出Excel /// </summary> /// <param name="dataGridView">表格控件</param> /// <param name="result">数据表格</param> /// <param name="fieldList">数据表字段名-说明对应列表</param> /// <param name="directory">目录</param> /// <param name="fileName">文件名</param> public void ExportExcel(System.Data.DataTable dt, Dictionary <string, string> fieldList, string directory, string fileName) { MyExportExcel(directory, fileName, (fiName) => { // BaseExportCSV.ExportCSV(dataGridView, dataView, fileName); // 2012.04.02 Author 增加新的导出Excel方法,非Com+方式,改用.Net控件 BaseExportExcel.ExportXlsByNPOI(dt, fieldList, fiName); }); }
/// <summary> /// 导出Excel /// </summary> /// <param name="dataGridView">表格控件</param> /// <param name="dataView">数据表格</param> /// <param name="directory">目录</param> /// <param name="fileName">文件名</param> public void ExportExcel(DevExpress.XtraGrid.Views.Grid.GridView grv, DataView dataView, string directory, string fileName) { MyExportExcel(directory, fileName, (fiName) => { // BaseExportCSV.ExportCSV(dataGridView, dataView, fileName); // 2012.04.02 Author 增加新的导出Excel方法,非Com+方式,改用.Net控件 BaseExportExcel.ExportXlsByNPOI(grv, dataView, fiName); }); }
private bool ValidateExport(SaveFileDialog saveFileDialog, out string fileName) { fileName = saveFileDialog.FileName; // 2012.04.02 Author 增加 判断文件是否被打开 if (BaseExportExcel.CheckIsOpened(fileName)) { LoadingUtil.ShowInformationMessage("Excel文件已经打开,请关闭后重试!", "提示信息", this); return(false); } if (System.IO.File.Exists(fileName)) { System.IO.File.Delete(fileName); } return(true); }
/// <summary> /// 根据SQL从数据获取数据,将DataTable中的数据保存到指定文件夹下保存成.csv文件格式 /// </summary> /// <param name="fileName">文件名</param> public void ExportToExcel(string fileName) { string commandText = string.Format(@"SELECT {0} 网点编号 ,CASE {1} WHEN 1 THEN '启用' WHEN 0 THEN '停用' ELSE '停用' END AS 启用 ,{2} 网点名称 ,{3} 所属网点 ,{4} 片区 ,{5} 类型 ,{6} 加盟方式 ,{7} 财务中心 ,{8} 结算中心 ,{9} 一级网点 ,{10} 二级中转费结算中心 ,{11} 省级网点 ,{12} 面单结算网点 ,{13} 统计网点 ,{14} 有偿派费费率 ,{15} 二级中转费费率 ,{16} 抛重费率 ,{17} 省份 ,{18} 城市 ,{19} 区县 FROM {20} WHERE {21} = 0 ORDER BY {22} ,{23} ,{24} " , BaseOrganizeEntity.FieldCode , BaseOrganizeEntity.FieldEnabled , BaseOrganizeEntity.FieldFullName , BaseOrganizeEntity.FieldParentName , BaseOrganizeEntity.FieldArea , BaseOrganizeEntity.FieldCategoryCode , BaseOrganizeEntity.FieldJoiningMethods , BaseOrganizeEntity.FieldFinancialCenter , BaseOrganizeEntity.FieldCostCenter , BaseOrganizeEntity.FieldCompanyName , BaseOrganizeEntity.FieldLevelTwoTransferCenter , BaseOrganizeEntity.FieldProvinceSite , BaseOrganizeEntity.FieldBillBalanceSite , BaseOrganizeEntity.FieldStatisticalName , BaseOrganizeEntity.FieldSendFee , BaseOrganizeEntity.FieldLevelTwoTransferFee , BaseOrganizeEntity.FieldWeightRatio , BaseOrganizeEntity.FieldProvince , BaseOrganizeEntity.FieldCity , BaseOrganizeEntity.FieldDistrict , BaseOrganizeEntity.TableName , BaseOrganizeEntity.FieldDeletionStateCode , BaseOrganizeEntity.FieldProvince , BaseOrganizeEntity.FieldCity , BaseOrganizeEntity.FieldDistrict); using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType, BaseSystemInfo.UserCenterDbConnection)) { DataTable organizeDataTable = new DataTable(); dbHelper.Fill(organizeDataTable, commandText); BaseExportExcel.ExportXlsByNPOI(organizeDataTable, null, fileName); } }