Add new Excel sheet - Dynamics Nav 2016

martynasmat
Member Posts: 1
I want to add multiple sheets for an Excel export functionality and after hours of searching the internet I have yet to come to a working solution.
I have added 2 new functions to the Excel Buffer table 370
I call these functions in a Page
This code throws the error: "A DotNet variable has not been instantiated. Tried calling AddWorksheet with Tabl Excel Buffer: AddNewSheet". Sorry if the translation is inaccurate, the original message was in another language.
After some experimentation I think the error comes up on the 2nd call of the AddNewSheet function - I marked it with a comment. I suspect something in the WriteSheet function inside the Excel Buffer table resets one of the DotNet Excel variables.
I set all the variables to RunOnClient = Yes.
I have added 2 new functions to the Excel Buffer table 370
AddNewSheet(SheetName : Text[250]) CurrentRow := 0; CurrentCol := 0; XlWrkShtWriter := XlWrkBkWriter.AddWorksheet(SheetName); IF SheetName <> '' THEN BEGIN XlWrkShtWriter.Name := SheetName; ActiveSheetName := SheetName; END; SetActiveSheet(SheetName : Text[250]) XlWrkShtWriter := XlWrkBkWriter.GetWorksheetByName(SheetName); IF SheetName <> '' THEN BEGIN XlWrkShtWriter.Name := SheetName; XlWrkShtWriter.Name := SheetName; END; XlWrkSht := XlWrkShtWriter.Worksheet;
I call these functions in a Page
FAMJobsExportExcel; // This function resets the buffer table and adds columns ExcelBuffer.CreateBook(ExcelFileName, 'testas'); ExcelBuffer.AddNewSheet('lapastt1'); ExcelBuffer.SetActiveSheet('lapastt1', ExcelFileName); ExcelBuffer.WriteSheet('', COMPANYNAME, USERID); DocumentsExportExcel; // This function resets the buffer table and adds columns ExcelBuffer.AddNewSheet('lapastt2'); // This line is probably responsible for the error ExcelBuffer.SetActiveSheet('lapastt2', ExcelFileName); ExcelBuffer.WriteSheet('', COMPANYNAME, USERID);
This code throws the error: "A DotNet variable has not been instantiated. Tried calling AddWorksheet with Tabl Excel Buffer: AddNewSheet". Sorry if the translation is inaccurate, the original message was in another language.
After some experimentation I think the error comes up on the 2nd call of the AddNewSheet function - I marked it with a comment. I suspect something in the WriteSheet function inside the Excel Buffer table resets one of the DotNet Excel variables.
I set all the variables to RunOnClient = Yes.
0
Answers
-
Hello,
Perhaps, there is a call of CLEAR(ExcelBuffer) in DocumentsExportExcel function.
If I'm not mistaken, ExcelBuffer.RESET can also clear variables.
Try to avoid call of these functions when book is already created, but not finished.0 -
[Topic moved from 'NAV/Navision Classic Client' forum to 'NAV Three Tier' forum]
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0
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