{"id":692,"date":"2024-02-04T14:26:42","date_gmt":"2024-02-04T06:26:42","guid":{"rendered":"https:\/\/live-d365fo.pantheonsite.io\/?p=692"},"modified":"2024-07-19T17:44:43","modified_gmt":"2024-07-19T09:44:43","slug":"how-to-export-to-excel-in-d365fo","status":"publish","type":"post","link":"https:\/\/dev-d365fo.pantheonsite.io\/how-to-export-to-excel-in-d365fo\/","title":{"rendered":"\u5982\u4f55\u5728D365FO\u5bfc\u51faExcel\u6587\u4ef6(How to export to EXCEL using X++ in D365 FO)"},"content":{"rendered":"\n

\u6b65\u9aa4<\/h2>\n\n\n\n

\u521b\u5efa\u4e00\u4e2aJob<\/p>\n\n\n\n

\"Create<\/figure>\n\n\n\n

<\/p>\n\n\n\n

\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801<\/a><\/strong><\/p>\n\n\n\n

\nclass RunnableClass2\n{\n    public static void main(Args _args)\n    {\n        CustTable custTable;\n        DocuFileSaveResult saveResult =\n    DocuFileSave::promptForSaveLocation(\"@ApplicationPlatform:OfficeDefaultWorkbookFileName\",\"xlsx\", null, \"excel create and export\");\n        if (saveResult&& saveResult.parmAction() != DocuFileSaveAction::Cancel)\n        {\n            saveResult.parmOpenParameters('web=1');\n            saveResult.parmOpenInNewWindow(false);\n            System.IO.Stream\n      workbookStream = new System.IO.MemoryStream();\n            System.IO.MemoryStream\n      memoryStream = new System.IO.MemoryStream();\n            using(var package = new OfficeOpenXml.ExcelPackage(memoryStream))\n            {\n                var worksheets = package.get_Workbook().get_Worksheets();\n                var worksheet = worksheets.Add(\"Sheet1\");\n                var cells = worksheet.get_Cells();\n                var currentRow=1 ;\n                \/*-------HEADER PART -------*\/\n                var cell = cells.get_Item(currentRow,1);\n                cell.set_Value(\"Customer Name\");\n                cell=null;\n                cell = cells.get_Item(currentRow,2);\n                cell.set_Value(\"Customer Address\");\n                \/*-------HEADER PART END-------*\/\n                \/*-------RECORD 1-------*\/\n                currentRow=2;\n                cell= cells.get_Item(currentRow, 1);\n                cell.set_Value(\"ABCD Trading\");\n                cell= null;\n                cell= cells.get_Item(currentRow, 2);\n                cell.set_Value(\"ABCD Complex, P.O Box :xxxxxx, XYZ Street\");\n                \/*-------RECORD 1 END-------*\/\n                \/*-------RECORD 2-------*\/\n                currentRow=3;\n                cell= cells.get_Item(currentRow, 1);\n                cell.set_Value(\"XYZ Trading\");\n                cell = null;\n                cell = cells.get_Item(currentRow, 2);\n                cell.set_Value(\"XYZ Complex, P.O Box :xxxxxx, ABC Street\");\n                \/*-------RECORD 2 END-------*\/\n                package.Save();\n            }\n            memoryStream.Seek(0,System.IO.SeekOrigin::Begin);\n            \/\/Download the file.\n            DocuFileSave::processSaveResult(memoryStream,saveResult);\n        }\n    }\n}\n<\/pre>\n\n\n\n

\u628a\u8fd9\u4e2aJob\u8bbe\u7f6e\u4e3a\u542f\u52a8\u9879\uff0c\u8fd0\u884c\u5b83\u540e\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u4ee5\u4e0b\u754c\u9762\uff1a<\/p>\n\n\n\n

\"Create<\/figure>\n\n\n\n

<\/p>\n\n\n\n

\u70b9\u51fb\u4e0b\u8f7d\u6309\u94ae\uff0cExcel\u5c31\u4f1a\u88ab\u5bfc\u51fa\u5230\u4e0b\u8f7d\u6587\u4ef6\u5939\u91cc\u9762<\/a><\/p>\n\n\n\n

\"Create<\/figure>\n\n\n\n

\u5173\u4e8eExcel\u5bfc\u51fa\u529f\u80fd\uff0c\u8bf7\u53c2\u8003\u4e00\u4e0b\u94fe\u63a5\uff1a<\/p>\n\n\n