Friday, January 10, 2014

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.



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.


3. Function SaveExcel Definition -

IF OpenUsingDocumentService('') THEN

IF NOT PreOpenExcel THEN

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.

Saurav Dhyani

No comments:

Post a Comment