{"title":"Report.SaveAsExcel(Text) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/report/reportinstance-saveasexcel-method/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/report/reportinstance-saveasexcel-method, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/report/reportinstance-saveasexcel-method","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Saves a report on the computer that is running the server as a Microsoft Excel (.xls) workbook.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"Report.SaveAsExcel(Text) Method","slug":"reportsaveasexceltext-method","at":0,"chars":4037},{"level":2,"title":"Syntax","slug":"syntax","at":262,"chars":65},{"level":2,"title":"Parameters","slug":"parameters","at":327,"chars":352},{"level":2,"title":"Return Value","slug":"return-value","at":679,"chars":238},{"level":2,"title":"Remarks","slug":"remarks","at":917,"chars":1620},{"level":3,"title":"Error conditions","slug":"error-conditions","at":1725,"chars":812},{"level":2,"title":"Example","slug":"example","at":2537,"chars":1366},{"level":2,"title":"Related information","slug":"related-information","at":3903,"chars":134}],"text":"# Report.SaveAsExcel(Text) Method\n> Version: _Available or changed with runtime version 1.0._\nSaves a report on the computer that is running the server as a Microsoft Excel (.xls) workbook.\n> NOTE\n> This method is supported only in Business Central on-premises.\n## Syntax\n```al\n[Ok := ]  Report.SaveAsExcel(FileName: Text)\n```\n## Parameters\nReport\nType: report-data-type\nAn instance of the report-data-type data type.\nFileName\nType: ../text/text-data-type\nThe path and the name of the file that you want to save the report as. The path must exist, the file must not be being used, and the server process must have permission to write to the file. Otherwise, you will get errors.\n## Return Value\n*[Optional] Ok*\nType: ../boolean/boolean-data-type\ntrue if the operation was successful; otherwise false. If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.\n## Remarks\nYou can use the SaveAsExcel method on the global Report object and on instances of a Report variable. If, at design time, you do not know the specific report that you want to run, then use the static version of the method: Report.SaveAsExcel(Integer, Text [, var Record])<report-saveasexcel-method>.\nWhen you call the SaveAsExcel method, the report is generated and saved to the file specified in \"FileName.\" The request page is not shown.\n> NOTE\n> The FileName parameter specifies a location on the computer that is running Business Central. If you call this method from a client, such as from an action on a page, then use the ../file/file-download-method method to download the .pdf file from the computer that is running the Business Central server to the computer that is running the client.\n### Error conditions\nThe method can fail in the following three ways:\n If the destination folder specified in FileName does not exist,\n If the file specified in FileName is being used, or\n If the Business Central server process does not have permission to write to the file specified in FileName.\nIf the destination folder that you specify in FileName does not exist, then you get the following error: The specified path is invalid.\nIf the file that you specify in FileName is being used, then you get the following error: An I/O exception occurred during the operation.\nIf the Business Central server process does not have permission to write to the file that you specify in FileName, then you get the following error: Either the caller does not have the required permission or the specified path is read-only.\n## Example\nThis example shows how to use the SaveAsExcel method to generate the report in the Business Central server and then download the Excel workbook file to the server.\n```al\nvar\n    MyReport: Report MyReport\n    TempFile: File;\n    FileNameAndPath: Text[250];\n    NewStream: InStream;\n    ToFile: Text[250];\n    ReturnValue: Boolean;\nbegin\n    // Specify that TempFile is opened as a binary file.\n    TempFile.TextMode(False);\n    // Specify that you can write to TempFile.\n    TempFile.WriteMode(True);\n\n    FileNameAndPath := 'C:\\Temp\\TempReport.xlsx';\n\n    // Create and open TempFile.\n    TempFile.Create(FileNameAndPath);\n    // Close TempFile so that the SaveAsExcel method can write to it.\n    TempFile.Close;\n\n    MyReport.SaveAsExcel(FileNameAndPath);\n\n    TempFile.Open(FileNameAndPath);\n    TempFile.CreateInStream(NewStream);\n\n    ToFile := 'MyReport.xlsx';\n\n    // Transfer the content from the temporary file on the\n    // server to a file on the client.\n    ReturnValue := DownloadFromStream(\n      NewStream,\n      'Save file to client',\n      '',\n      'Excel File *.xlsx| *.xlsx',\n      ToFile\n    );\n\n    // Close the temporary file.\n    TempFile.Close();\nend;\n```\nYou can create an action on a page and set the action to run this code. When you run the action, the Export File dialog box opens. Choose Save to save the file to the client.\n## Related information\nreport-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}