Skip to main content

Microsoft Dynamics NAV 2016 - Save Export to Excel

Hi All,


If you remember we discussed in Past about Saving Excel File in NAV 2013 R2. This article is Re-writing the Same Article for Microsoft Dynamics NAV 2016.

If you are looking for same solution for Microsoft Dynamics NAV 2013 and NAV 2013 R2 please refer article -  NAV 2013 & NAV 2013 R2 - Save Export to Excel


This article discuss the steps required for Microsoft Dynamics NAV 2016.



1. SETUP -

Create a New Field in Table 409 SMTP Mail Setup for Specifying the Path. Add the Field on Page 409 SMTP Mail Setup as shown below.


2. Code Changes -

Changes in Table 370 Excel Buffer -

a. Created Two Functions CreateBookAndSaveExcel & SaveExcel.

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

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

c. 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


3. Let's Execute By Running the Report with new Function.

Create a new report which export data from customer table and save the File is the path specified in the SMTP Setup. As shown below instead of using CreateBookAndOpenExcel we use CreateBookAndSaveExcel.


And once we execute the Report, the report is saved in the Path where we setup in the SMTP Setup.


Objects can be downloaded from - Dynamics User Group or Skydrive.

File Name  - NAV 2016_Save to Excel

** If you are planning to merge it on a custom database then the attachment have before and after the text files are available in the download files.

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

Your comments and feedback are welcome. Stay tuned for more.

Regards,
Saurav Dhyani
saurav-nav.blogspot.in

Comments

Popular posts from this blog

VIEW SERVER STATE permission on SQL Server?

Hi all, Sometime While trying to Login into a database we face an error message as shown below. --------------------------- Microsoft Dynamics NAV Classic --------------------------- You cannot start Microsoft Dynamics NAV Classic because you do not have the VIEW SERVER STATE permission on SQL Server. Contact your system administrator. --------------------------- OK    ---------------------------

NAV 2013 R2 - Cumulative update 12 Released.

Hi all, Please find below the details of  Cumulative Update 12 released for Microsoft Dynamics NAV 2013 R2. Title - Cumulative Update 12 for Microsoft Dynamics NAV 2013 R2 Build No. - 38053 Release Date - October, 2014 Local Version Included - AU, AT, BE, CH, DE, DK, ES, FI, FR, IS, IT, NA, NL, NO, NZ, SE, UK, RU Download Link Note: Implementing this cumulative update will require a database conversion unless you have already implemented update rollup 5.

NAV 2013 Upgrade Part III - Data Upgrading.

Hi all, As per agenda we need to discuss the data upgrade in NAV 2013. The process is similar to what used to be till NAV 2009 R2 but with some changes. Let's start the process. Remember -  1) You can only upgrade a database to NAV 2013 from NAV 2009 SP1 / R2 SQL Only. 2) The Synchronization of users with SQL Server is no more required.