How to declare a DonNet System.Object variable in NAV2013R2?

kirkostaskirkostas Member Posts: 127
edited 2014-09-30 in NAV Three Tier
I want to use the Excel's Workbook Method SaveAs because I want to change the Save as Type and save my workbook in Formatted Text (Space delimited) (*.prn).

But this method has many parameters of type System.Object and I can't find this assembly and I am using NAV variables instead. Text, boollean,integer but it doesn't work and in return I get this error message:

A dotnet variable has not been instantiated. Attempting to call Microsoft.Office.Interop.Excel.Workbook.SaveAs in Table Excel Buffer: SaveAs

Does this means that the method is not initiated properly with the correct variables? But how can I declare a System.Object variable in NAV?

This is the code I am using:
XlWrkBk.SaveAs(
  FileName,FileFormat,Password,WriteResPassword,ReadOnlyRecommended,CreateBackup,
  XLSAVEASACCESSMODE,ConflictResolution,AddToMru,TextCodepage,TextVisualLayout,Local);
kirkostas

Comments

  • yukonyukon Member Posts: 361
    Hi kirkostas,

    Below two link will be help to you.

    _Workbook.SaveAs Method : http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel._workbook.saveas%28v=office.14%29.aspx

    Problem with Workbook.SaveAs :
    http://social.msdn.microsoft.com/Forums ... m=exceldev


    I copied the sample code from Workbook.Saveas topic
    xlWorkBook.SaveAs("C:\\MyExcelTestTest.xlsx",
                System.Reflection.Missing.Value,
                System.Reflection.Missing.Value,
                System.Reflection.Missing.Value,
                false,
                false,
                Excel.XlSaveAsAccessMode.xlShared,
                false,
                false,
                System.Reflection.Missing.Value,
                System.Reflection.Missing.Value,
                System.Reflection.Missing.Value);
    

    Best Regards,
    Yukon
    Make Simple & Easy
  • kirkostaskirkostas Member Posts: 127
    I am familiar with those links. But how can I pass a System.Object variable from NAV? Also I searched for System.Reflection but it didn't gave me the System.Reflection.Missing.Value !

    Do you use this code in Nav or its just an example of how it will looks like in C#?

    I tried to use the following variables but no luck!
    Name	DataType	Subtype	Length
    XlFileFormat	DotNet	Microsoft.Office.Interop.Excel.XlFileFormat.'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'	
    XlSaveAsAccessMode1	DotNet	Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'	
    XlSaveConflictResolution	DotNet	Microsoft.Office.Interop.Excel.XlSaveConflictResolution.'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'	
    XlTextVisualLayoutType	DotNet	Microsoft.Office.Interop.Excel.XlTextVisualLayoutType.'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'	
    
    kirkostas
  • jordi79jordi79 Member Posts: 275
    Hi Kirkostas,

    Did you find a solution to your problem? I have a similar problem. I need to call a DotNet Method but I need to pass some System.Object parameters. These are optional parameters, but I guess optional parameters are not supported in NAV. Therefore I have to explicitly pass these "empty" parameters anyhow.

    Much appreciated...
Sign In or Register to comment.