Excel Buffer NAV 2015 - multiple sheets

martinher562
Member Posts: 50
Hello NAV Experts,
I am having a really difficult time adding an additional sheet to an excel export.
Currently I have the below code on the OnPostReport() trigger and this works fine and I add data to this sheet:
//If export to excel then create excel spreadsheet
IF NOT CreateExcel THEN
CurrReport.BREAK;
ExcelBuffer.CreateBookAndOpenExcel('INFO','Report',COMPANYNAME,USERID) ;
I would like to add a new sheet in the same workbook.
I have tried to follow this: http://www.kopija.in.rs/dynamicsnav/add-multiple-excel-worksheets-dynamics-nav-2013-r2/
and this: https://saurav-nav.blogspot.nl/2015/07/nav-2013-r2-multiple-sheets-in-excel.html
However, I keep getting error messages that variables do not exist and I add one and then just another error message about another variable.
For example: https://dynamicsuser.net/nav/f/beginners/22098/export-to-excel-on-multi-worksheets-using-excel-buffer
This says to add a function to the buffer table 370:
AddSheet()
XlWrkSht := XlWrkBk.Worksheets.Add();
So I add the function and then it says "variable XlWrkSht unknown". So I created it and then I get the same error message but for "XlWrkBk".
On post report trigger I tried adding : ExcelBuffer.AddSheet('NewSheet2') and I get error message that variable AddSheet is unknown.
My question is: Can someone explain how to add a new sheet to the excel export ? Also How to load that sheet with information once is created?
Please explain if I need variables and where the CAL code should be placed.
Thank you all for your time in advance !
I am having a really difficult time adding an additional sheet to an excel export.
Currently I have the below code on the OnPostReport() trigger and this works fine and I add data to this sheet:
//If export to excel then create excel spreadsheet
IF NOT CreateExcel THEN
CurrReport.BREAK;
ExcelBuffer.CreateBookAndOpenExcel('INFO','Report',COMPANYNAME,USERID) ;
I would like to add a new sheet in the same workbook.
I have tried to follow this: http://www.kopija.in.rs/dynamicsnav/add-multiple-excel-worksheets-dynamics-nav-2013-r2/
and this: https://saurav-nav.blogspot.nl/2015/07/nav-2013-r2-multiple-sheets-in-excel.html
However, I keep getting error messages that variables do not exist and I add one and then just another error message about another variable.
For example: https://dynamicsuser.net/nav/f/beginners/22098/export-to-excel-on-multi-worksheets-using-excel-buffer
This says to add a function to the buffer table 370:
AddSheet()
XlWrkSht := XlWrkBk.Worksheets.Add();
So I add the function and then it says "variable XlWrkSht unknown". So I created it and then I get the same error message but for "XlWrkBk".
On post report trigger I tried adding : ExcelBuffer.AddSheet('NewSheet2') and I get error message that variable AddSheet is unknown.
My question is: Can someone explain how to add a new sheet to the excel export ? Also How to load that sheet with information once is created?
Please explain if I need variables and where the CAL code should be placed.
Thank you all for your time in advance !
0
Best Answers
-
seems that variable xlwrkbkwriter (type ...WorkbookWriter) is not created.
maybe this code sample is helpful for you: http://www.kopija.in.rs/dynamicsnav/add-multiple-excel-worksheets-dynamics-nav-2013-r2/
best regards
Franz Kalchmair, MVP
Alias: Jonathan Archer
please like / agree / verify my answer, if it was helpful for you. thx.
Blog: http://moxie4nav.wordpress.com/5 -
Have a read through the blog again, it says...Also, there is a difference that we cannot use standard function CreateBookAndOpenExcel – because it is used for single worksheet case scenario – but we must “close” Excel manually by calling standard functions CloseBook, OpenExcel, GiveUserControl on Excel Buffer.
Look at the code in the OnRun() trigger of the test codeunit - you need to use that instead.5
Answers
-
i wrote a posting about that topic.
follow https://moxie4nav.wordpress.com/2016/07/24/working-with-excel-documents-in-nav/
best regards
Franz Kalchmair, MVP
Alias: Jonathan Archer
please like / agree / verify my answer, if it was helpful for you. thx.
Blog: http://moxie4nav.wordpress.com/0 -
@archer89 Thank you. Now I am having a problem.
I was able to create and understand the excel buffer functions better. However, when I follow this tutorial: https://saurav-nav.blogspot.nl/2015/07/nav-2013-r2-multiple-sheets-in-excel.html
I keep getting the attached error message:
A DotNet variable has not been instantiated. Attempting to call Microsoft.Dynamics.Nav.OpenXml.Spreadsheet.WorkbookWriter.AddWorksheet in Table Excel Buffer: WriteSheet.0 -
seems that variable xlwrkbkwriter (type ...WorkbookWriter) is not created.
maybe this code sample is helpful for you: http://www.kopija.in.rs/dynamicsnav/add-multiple-excel-worksheets-dynamics-nav-2013-r2/
best regards
Franz Kalchmair, MVP
Alias: Jonathan Archer
please like / agree / verify my answer, if it was helpful for you. thx.
Blog: http://moxie4nav.wordpress.com/5 -
@archer89 I was able to create the function, but when I call the function. Nothing happens, not even an error code.
This is my code:
OnPostReport()
//If export to excel then create excel spreadsheet
IF NOT CreateExcel THEN
CurrReport.BREAK;
MakeExcelInfoSheet;
ExcelBuffer.CreateBookAndOpenExcel('Item','Report',COMPANYNAME,USERID) ;
ExcelBuffer.AddNewSheet('Data');0 -
You need to call the GiveUserControl() function at the end - this will make the Excel Application visible.0
-
@Kishorm Now I get excel to open, only the Item and information tab and not the "Data" tab; which is the tab that the new function is using.
The function is the code from this page (literally cope and paste): http://www.kopija.in.rs/dynamicsnav/add-multiple-excel-worksheets-dynamics-nav-2013-r2/
Thank you !
0 -
Have a read through the blog again, it says...Also, there is a difference that we cannot use standard function CreateBookAndOpenExcel – because it is used for single worksheet case scenario – but we must “close” Excel manually by calling standard functions CloseBook, OpenExcel, GiveUserControl on Excel Buffer.
Look at the code in the OnRun() trigger of the test codeunit - you need to use that instead.5 -
@Kishorm You have soo helpful. I finally go it to work. However, the same data gets written into both spreadsheets. I see that in the blog a code unit is created, but I would like to do it in the report triggers.
Any suggestions on how to get it done ?
This is the code I used to get more than 1 spreadsheet created.
OnPostReport()
ExcelBuffer.CreateBook('Data');
ExcelBuffer.WriteSheet('Other',COMPANYNAME,USERID);
ExcelBuffer.AddNewSheet('Test') ;
ExcelBuffer.CloseBook;
ExcelBuffer.OpenExcel;
ExcelBuffer.GiveUserControl;
@Kishorm again thanks for all the help and sticking with me through this problem.0 -
Have a look at the test codeunit in the blog and follow the same structure, i.e...
1) For each sheet you want to create populate data and the call AddNewSheet
2) Do not call the WriteSheet function in your report (this is done in the AddNewSheet function)
3) At the end CloseBook, OpenExcel & GiveUserControl functions0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions