Hi all!
I am very beginner with navision. I got as task to transform a report from Ms Dynamics Navision2009 into 2013.
As improvement I should use DOTNET excel interop instead automation...and i got stuck in this.
I declared dotnet variables, marked them to run on client and wrote next code :
ExcelApp := ExcelApp.ApplicationClass;
IF ISNULL(ExcelApp) THEN
ERROR(Text000);
Template := '';
ExcelSheet := ExcelApp.Workbooks.Add(Template);
IF ISNULL(ExcelWbk) THEN
ERROR('Fehler ExcelWbK = NULL');
ExcelSheet := ExcelWbk.Worksheets.Item(1);
IF ISNULL(ExcelSheet) THEN
ERROR('Fehler ExcelSheet = NULL');
where
ExcelApp DotNet Microsoft.Office.Interop.Excel.ApplicationClass.'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
ExcelWbk DotNet Microsoft.Office.Interop.Excel.Workbook.'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
ExcelSheets DotNet Microsoft.Office.Interop.Excel.Worksheets.'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
ExcelSheet DotNet Microsoft.Office.Interop.Excel.Worksheet.'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
ExcelWorkbooks DotNet Microsoft.Office.Interop.Excel.Workbooks.'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
Template Variant
The proogram break into this: ExcelSheet := ExcelApp.Workbooks.Add(Template);
In debugger :
ExcelApp - <Unknown> - "DotNet on Client ""Microsoft.Office.Interop.Excel.ApplicationClass"""
ExcelWbk - <Uninitialized> - "DotNet on Client ""Microsoft.Office.Interop.Excel.Workbook"""
The question: How to initialize excel workbook? Or what I do wrong ... There is somewhere a good example related to this subject?
Thanks in advance to anyone involved!
Victor
0
Comments
Gunnar Gestsson
Microsoft Certified IT Professional
Dynamics NAV MVP
http://www.dynamics.is
http://Objects4NAV.com
http://closedxml.codeplex.com/
It's super fast and way easyer to use than OpenXML. I bulit a wrapper Codeunit for our solutions. Took me about 20 hours and now the whole team is using it. We got that time back within a few months and have more features than ExcelBuffer now. There are some issues with color selection by Color-name and date formating while reading but its still worth it.
Eighter way; you need to call a constructor of your Interop-Class before you can use it any other way. In the C/AL Symbol Menu (F5 in the C/AL Editor) there is a seperate section for the constructors.
Yes I know that NAV 2013 uses automations instead of DotNet.
This is the import one, might be handy
This one might be more of interest that is the export
I thank you for your answers !
I have made some tiny steps and got a new problem:
the code:
ExcelApp := ExcelApp.ApplicationClass;
IF ISNULL(ExcelApp) THEN
ERROR(' Excel App is null ');
Template := '';
ExcelWbk := ExcelApp.Workbooks.Add(Template);
IF ISNULL(ExcelWbk) THEN
//EXIT;
ERROR(' Excel workbook is null ');
ExcelSheet1 := ExcelWbk.Worksheets.Item(1);
ExcelSheet1.Name := 'page1';
IF ISNULL(ExcelSheet1) THEN
// EXIT;
ERROR(' Excel worksheet1 is null ');
ExcelSheet2 := ExcelWbk.Worksheets.Add(DotNetMissing,ExcelSheet1,DotNetMissing,DotNetMissing);
//ExcelSheet := ExcelWbk.Worksheets.Item(2);
ExcelSheet2.Name := 'page2';
IF ISNULL(ExcelSheet2) THEN
// EXIT;
ERROR(' Excel worksheet is null ');
////////////////////////////////////////
ExcelApp.Visible := TRUE;
fails in method Worksheet.Add() with message : "Add method of Sheets class failed" ....
Name DataType Subtype Length
DotNetMissing DotNet System.Reflection.Missing.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
I have tried to reproduce the same interop usage in C# and worked .... I guess something is not ok with parameter list...
Has anyone have a clue?