System.Data.DataTable dt = _CORACLELogisticsData.GetDataTable("select PORTENG from P_Port order by PORTENG "); //System.Data.DataTable dt = _CORACLEData.GetDataTable(" select CUSTOMCODE from P_CUSTOM where CUSTOMTYPE = '供应商' and INSTR(CUSTOMERTYPE,'船公司')> 0 order by CUSTOMCODE Asc"); Console.WriteLine(dt.Rows.Count); ExcelWorksheet workSheet; FileInfo existingFile = new FileInfo(@"D:项目运价大本营标准格式运价大本营供应商标准表格(2).xlsx"); using (var p = new ExcelPackage(existingFile)) { workSheet = p.Workbook.Worksheets.Add("目的港"); for (int i = 0; i < dt.Rows.Count; i++) { workSheet.Cells[i + 1, 1].Value = dt.Rows[i][0].ToString(); } p.SaveAs(existingFile); Console.WriteLine("导入成功"); }
需添加EPPlus.dll,有需要的请自行百度下载