步骤
创建一个Job
class RunnableClass2 { public static void main(Args _args) { CustTable custTable; DocuFileSaveResult saveResult = DocuFileSave::promptForSaveLocation("@ApplicationPlatform:OfficeDefaultWorkbookFileName","xlsx", null, "excel create and export"); if (saveResult&& saveResult.parmAction() != DocuFileSaveAction::Cancel) { saveResult.parmOpenParameters('web=1'); saveResult.parmOpenInNewWindow(false); System.IO.Stream workbookStream = new System.IO.MemoryStream(); System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(); using(var package = new OfficeOpenXml.ExcelPackage(memoryStream)) { var worksheets = package.get_Workbook().get_Worksheets(); var worksheet = worksheets.Add("Sheet1"); var cells = worksheet.get_Cells(); var currentRow=1 ; /*-------HEADER PART -------*/ var cell = cells.get_Item(currentRow,1); cell.set_Value("Customer Name"); cell=null; cell = cells.get_Item(currentRow,2); cell.set_Value("Customer Address"); /*-------HEADER PART END-------*/ /*-------RECORD 1-------*/ currentRow=2; cell= cells.get_Item(currentRow, 1); cell.set_Value("ABCD Trading"); cell= null; cell= cells.get_Item(currentRow, 2); cell.set_Value("ABCD Complex, P.O Box :xxxxxx, XYZ Street"); /*-------RECORD 1 END-------*/ /*-------RECORD 2-------*/ currentRow=3; cell= cells.get_Item(currentRow, 1); cell.set_Value("XYZ Trading"); cell = null; cell = cells.get_Item(currentRow, 2); cell.set_Value("XYZ Complex, P.O Box :xxxxxx, ABC Street"); /*-------RECORD 2 END-------*/ package.Save(); } memoryStream.Seek(0,System.IO.SeekOrigin::Begin); //Download the file. DocuFileSave::processSaveResult(memoryStream,saveResult); } } }
把这个Job设置为启动项,运行它后我们可以看到以下界面:
关于Excel导出功能,请参考一下链接: