Quantcast
Channel: NAV Three Tier — mibuso.com
Viewing all articles
Browse latest Browse all 10069

NAV2016 - Usage of Excel Interop

$
0
0
Hi,

I'm exporting data and create charts to a new Excel file using the Excel Interop (.NET). But when I create a new workbook, only 1 sheet is created.
But my charts need to be added to separate sheets, for that I'm using the Workbook.Sheets.Add(before,after,number,type) - function.
Now I'm getting the error "Method Add of class Sheets failed".

the variables used (all marked with 'run on client'):
  • XlApplication: Microsoft.Office.Interop.Excel.ApplicationClass.'Microsoft.Office.Interop.Excel'
  • XlWorkBook: Microsoft.Office.Interop.Excel._Workbook.'Microsoft.Office.Interop.Excel'
  • XlWorkSheet_: Microsoft.Office.Interop.Excel._Worksheet.'Microsoft.Office.Interop.Excel'
  • missing:System.Reflection.Missing.'mscorlib'

My code looks the following:
XlApplication:=XlApplication.ApplicationClass;
IF ISNULL(XlApplication) THEN
  ERROR(Text000);
XlApplication.Visible(FALSE);
XlWorkBook:= XlApplication.Workbooks.Add(XLWBATemplate.xlWBATWorksheet);
XlWorkSheet_ := XlWorkBook.ActiveSheet;
XlWorkSheet_.Name:='Demo1';
XlWorkSheet:=XlWorkBook.Sheets.Add(missing,XlWorkBook.Sheets.Item(XlWorkBook.Sheets.Count),missing,missing);
XlWorkSheet_.Name:='Demo2';
XlWorkBook.SaveCopyAs(FileName)

The error occurs on line:
XlWorkSheet:=XlWorkBook.Sheets.Add(missing,XlWorkBook.Sheets.Item(XlWorkBook.Sheets.Count),missing,missing);
because in the Add-function all 4 parameters are marked as optional, but in C/AL those parameters need to be added. Due to testing I figured out that the error is thrown because of the optional parameters, but I'm actually currently stuck in continuing my work.

I also tried to indicate to Excel that it needs to add 3 sheets when creating a new workbook using the function "SheetsInNewWorkbook", but that didn't change anything in the Excel file, only 1 sheet was created.

Is there anyone who knows how to deal with this problem?

Kind Regards,
Tom


Viewing all articles
Browse latest Browse all 10069

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>