Monday, February 27, 2017

How To save excel File in MS Dynamics NAV From Excel Buffer? Anand Blog


How To save excel File from Excel Buffer in Dynamics NAV 2016?


This article is about the steps required to save an excel which was generated from Excel Buffer in Microsoft Dynamics NAV 2016.

Step 1 . 

In this article I am taking my preferred Location To Save the Excel File the location is at a Setup table.So you have to create some new functions in your excel Buffer Table. Please see the reference screen.

How to save excel buffer in navision 2017?

Copy Paste the Standard Function :- 

Named CreatebookandOpenexcel and create a new Function SaveExcel
You can also copy paste the code

CreateBookAndSaveExcel(FileName : Text;SheetName : Text[250];ReportHeader : Text;CompanyName2 : Text;UserID2 : Text)
CreateBook(FileName,SheetName);
WriteSheet(ReportHeader,CompanyName2,UserID2);
CloseBook;
Saveexcelby;
LOCAL Saveexcelby()
BWsetup.GET;
IF OpenUsingDocumentService('') THEN
  EXIT;
IF NOT PreOpenExcel THEN
  EXIT;
FileNameClient := FileManagement.DownloadTempFile(FileNameServer);
FileNameClient := FileManagement.MoveAndRenameClientFile(FileNameClient,FriendlyName,BWsetup."Vendor  Stmnt File Path");




I think you need to change the setup table only according to your need and requirement of your architecture. I am not deleteing any code from screenshot all these function are already defined in this table.


If you get any error in saving excel Buffer table then do reply me in Comment section.

Step 2 . How to call the Function?



CreateExcelBook()
IF BWSetup.GET THEN;
ExcelBuf.SetFriendlyFilename(FORMAT(Vendor."No.")+FORMAT(TODAY,0,'<Day,2><Month,2><Year4>')+'.xlsx');
ExcelBuf.CreateBookAndSaveExcel('','Statement details','',COMPANYNAME,USERID);
ExcelBuf.DELETEALL;



To call the function you need to modify your CreateExcelBook Function.
Please Note :-
SetfriendlyFilename is an inbuilt function of ExcelBuffer in NAV 2016.
I hope I had Explained the steps clearly if you like the post and it helped you then please share our post and subscribe to our blog post.

Thanks.
You can also check the following Links :-