Skip to main content

Notifications

Microsoft Dynamics NAV (Archived)

Converting XLS to XLSX File

Posted on by 5,567

Hi

I'm trying to save XLS file as XLSX file using below code.
XlApp DotNet Microsoft.Office.Interop.Excel.ApplicationClass.'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' 
XlWrkBk DotNet Microsoft.Office.Interop.Excel.Workbook.'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' 
XlWrkSht DotNet Microsoft.Office.Interop.Excel.Worksheet.'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' 
XlHelper DotNet Microsoft.Dynamics.Nav.Integration.Office.Excel.ExcelHelper.'Microsoft.Dynamics.Nav.Integration.Office, Version=10.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'  
ExcelXlSaveAsAccessMode DotNet Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' 
ExcelFileFormat DotNet Microsoft.Office.Interop.Excel.XlFileFormat.'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' 

XlsFilename := C:\123.xls;
XlsxFilename := C:\123.xlsx;
XlApp := XlApp.ApplicationClass;
XlHelper.CallOpen(XlApp,XlsFilename);
XlWrkBk := XlApp.ActiveWorkbook;

XlWrkBk.SaveAs(XlsxFilename,ExcelFileFormat.xlWorkbookDefault,'','', FALSE, FALSE,
  ExcelXlSaveAsAccessMode.xlNoChange, FALSE, FALSE, FALSE, FALSE, FALSE);
XlWrkBk.Close(FALSE,'',TRUE);

but receiving the below error.

Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))

*This post is locked for comments

  • Suggested answer
    Binesh Profile Picture
    Binesh 7,885 on at
    RE: Converting XLS to XLSX File

    Hey, i checked in NAV 2017. its working.

    only the thing is you have to re-declare the variables again.

    Better, Copy XlHelper variable from Table 370.

  • Rajasekhar@MS Profile Picture
    Rajasekhar@MS 5,567 on at
    RE: Converting XLS to XLSX File

    Hi

    Receiving this error, can you check in 2017(I think you are checking in 2016)

    Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))

  • Verified answer
    Binesh Profile Picture
    Binesh 7,885 on at
    RE: Converting XLS to XLSX File

    Hello Raj,

    see the bellow screenshot, this solution works perfectly. you can also use your old_filename with .xlsx 

    001.png

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans