Skip to main content

NAV 2013 & NAV 2013 R2 - Save Export to Excel

Hi all,

In Last post we had seen how to use export to Excel Reports in NAV 2013.

The Next question asked to me is with older version with some code we used to able to save the Report at a specified path instead of opening it. Is it possible with NAV 2013 and later?

So here it is, we can again create some functions in excel buffer and save the excel files.

This article Applies to Microsoft Dynamics NAV 2013 & NAV 2013 R2. Attached Screens are from NAV 2013 R2.


Steps 

SETUP -

1. I created a New Field in Table 409 SMTP Mail Setup for Specifying the Path.



2. Added the Field on Page 409 SMTP Mail Setup as shown below.



Changes in Table 370 Excel Buffer -

1. Created Two Functions CreateBookAndSaveExcel & SaveExcel.

2. Function CreateBookAndSaveExcel Definition- 
 * Copy of CreateBookandOpenExcel with some code changed.


CODE -
-------------------------------------------------------------------------------------------------------------
CreateBook(SheetName);
WriteSheet(ReportHeader,CompanyName,UserID2);
CloseBook;
SaveExcel;
-------------------------------------------------------------------------------------------------------------

3. Function SaveExcel Definition -



CODE
-------------------------------------------------------------------------------------------------------------
SmtpSetup.GET;
IF OpenUsingDocumentService('') THEN
  EXIT;

IF NOT PreOpenExcel THEN
  EXIT;

FileNameClient := FileManagement.DownloadTempFile(FileNameServer);
FileNameClient := FileManagement.MoveAndRenameClientFile(FileNameClient,'Book1.xlsx',SmtpSetup."Save Excel Report");
-------------------------------------------------------------------------------------------------------------

Variables in Function Save Excel-

Name DataType         Subtype
FileNameClient Text
SmtpSetup  Record SMTP Mail Setup

Changes in Report 120 Aged Accounts Receivable -

In Function CreateExcelbook New Function call (save Instead of Open)



When i Run the Report it will get saved in D Drive (path Specified in SMTP Setup).

Changes have been done on four objects. Objects can be downloaded from -

Dynamics User Group NAV For 2013 and  Dynamics User Group NAV For 2013 R2

or my Skydrive. There are two files one for NAV 2013 and one for NAV 2013 R2.

NAV 2013 File Name  - NAV 2013_Save to Excel
NAV 2013 R2 File Name - NAV 2013 R2 _ Save to Excel

You can also make it more generic by passing File Name from the Report Itself.

Regards,
Saurav Dhyani

Comments

  1. Microsoft Dynamics NAV
    ---------------------------

    A call to Microsoft.Dynamics.Nav.OpenXml.Spreadsheet.WorkbookWriter.Create failed with this message: Access to the path 'C:\ProgramData\Microsoft\Microsoft Dynamics NAV\90\Server\MicrosoftDynamicsNavServer$DynamicsNAV90\users\default\DESKTOP-UNIKUL1\RAKSHITH UNIKUL\TEMP\__TEMP__2964166186264430ae9bd5c3dcdcc553.tmp.xlsx' is denied.
    ---------------------------
    OK
    ---------------------------



    Hi all I follow each and every step but this type of error occur.
    Can you please help me to resolve this issue.

    ReplyDelete
    Replies
    1. Make sure that service account (account used to run services), have write permission to folder - C:\ProgramData\Microsoft\Microsoft Dynamics NAV\90\

      Delete

Post a Comment

Popular posts from this blog

BC 21 and Higher - PowerShell Cmdlet (Replacement of Business Central Administration).

Hi Readers, As discussed in last article about deprecating of Business Central Administration, there are few common actions that we use in administration till Business Central 20. For our on-prem customers, we will still require doing activities. As Microsoft suggest we need to start using PowerShell cmdlet.    Let's see how to do those via PowerShell, or Administration Shell. I will be keep adding commands as you comment to this article.

Send Mail with Attachment From Navision.

Hi all, We have seen how to save a report into PDF and how to send mail to a customer. Let's link these two post in one i.e. Mailing statement to a customer into PDF Format. This article is part of the Series. Please Refer  Table of Content here . If you have the old objects set let me brief you what I will be changing - 

MSDYN365BC - Data Upgrade To Microsoft Dynamics 365 Business Central on premises.

Hi Readers, We have already talked about the number of steps for upgrading to Business Central on Premises from different NAV versions. After that article, I received multiple requests for an article which list down steps for Data Migration. In this article, we will discuss steps of data migration to MSDYN365BC (on-Prem) from NAV 2017. For this article, I am considering a Cronus Demo Database without any customization. For an actual upgrade project, we will have to complete object merge using compare and Merge process. After the Merge Process, the next step is data migration. Let's discuss those steps. Direct Upgrade to Microsoft Dynamics 365 Business Central (on-Prem) is from following versions - 1. NAV 2015. 2. NAV 2016. 3. NAV 2017. 4. NAV 2018.