Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

Export To Excel Problem

Posted on by Microsoft Employee

Hi,

I am using dotnet variables in nav to  do this.

I followed this link to do the export to excel.

http://forum.mibuso.com/discussion/56735/dotnet-and-excel-in-nav2013.

when I run the report I am getting following error message

"A call to System.__ComObject.Open failed with this message: The type of one or more arguments does not match the method's parameter type."

I have given the following parameters for open function.


XlWrkBk:=XlApp.Workbooks.Open('Excelfile',0,TRUE,5,'','',TRUE,EnumToInt(XlPlatformFullName,

                                                         'xlWindows'),'\t',FALSE,FALSE,0,TRUE,1,0);

I am using NAV 2015 version

Can any body give some useful example or suggestion

Thanks in advance

*This post is locked for comments

  • Suggested answer
    HILBE Profile Picture
    HILBE 300 on at
    RE: Export To Excel Problem

    Hi,

    you have to do this this way

    ExcelApplicationClass_l := ExcelApplicationClass_l.ApplicationClass;

    ExcelWorkbook_l := ExcelApplicationClass_l.Workbooks.Open(FileName_v,0,TRUE,5,'','',TRUE,ExcelXLPlatform_l.xlWindows,'\t',FALSE,FALSE,0,TRUE,1,0);

    Name DataType Subtype Length

    ExcelApplicationClass_l DotNet Microsoft.Office.Interop.Excel.ApplicationClass.'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'

    ExcelWorkbook_l DotNet Microsoft.Office.Interop.Excel.Workbook.'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'

    ExcelXLPlatform_l DotNet Microsoft.Office.Interop.Excel.XlPlatform.'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'

    This is a problem, because you have to assign the parameter complete correctly.

    You're EnumToInt(...) will not work in NAV. You have to use dotnet variable for that:

    Microsoft.Office.Interop.Excel.XlPlatform.'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'

    best regards

    Robert

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Export To Excel Problem

    I'm getting an error in NAV 2015 when trying to import an password protected NAV 2015 file, do you have any ideas on how to counter this?

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
  • Verified answer
    keoma Profile Picture
    keoma 32,675 on at
    RE: Export To Excel Problem

    hi,

    better you use table excel buffer or use the same global vars as in this table like XlWrkBkReader (Microsoft.Dynamics.Nav.OpenXml.Spreadsheet.WorkbookReader.'Microsoft.Dynamics.Nav.OpenXml, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35') to work with excel files.

    using com objects is always an adventure.

    there goto function OpenBook:

    ...

    XlWrkBkReader := XlWrkBkReader.Open(FileName);

    IF XlWrkBkReader.HasWorksheet(SheetName) THEN BEGIN

     XlWrkShtReader := XlWrkBkReader.GetWorksheetByName(SheetName);

    ...

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Export To Excel Problem

    we have checked with this below  link for parameters.

    msdn.microsoft.com/.../microsoft.office.interop.excel.workbooks.open.aspx

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans