DotNet ClosedXML Error

csimoneaux0527csimoneaux0527 Member Posts: 21
edited 2014-09-08 in NAV Three Tier
On the Report Comment Line I have added code to export to Excel. I am trying for the first time to utilize the following code.
Report line of code call
NewRow := NewRow + 1;
NewColumn := NewColumn + 1;
ExcelBuf.AddCell(NewRow, NewColumn,'Customer Comments',FALSE,TRUE,FALSE,FALSE,'',ExcelBuf."Cell Type"::Text,'',0);


ExcelBuffer – Function

AddCell(CurrentRow_1 : Integer;CurrentCol_1 : Integer;Value : Variant;IsFormula : Boolean;IsBold : Boolean;IsItalics : Boolean;IsUnderline : Boolean;NumFormat : Text[30];CellType : 'Number,Text,Date,Time';Font : Text;FontSize : Integer)

GlobalRowNo := CurrentRow_1;
GlobalColumnNo := CurrentCol_1;

XlWrkShtDotNet.Cell(GlobalRowNo,GlobalColumnNo).Style.Font.Bold := IsBold;

Variable –
Name DataType Subtype
XlWrkShtDotNet DotNet ClosedXML.Excel.IXLWorksheet.'ClosedXML, Version=0.59.0.0,
Culture=neutral, PublicKeyToken=fd1eb21b62ae805b'

As soon as the following line is read ...
XlWrkShtDotNet.Cell(GlobalRowNo,GlobalColumnNo).Style.Font.Bold := IsBold;

I receive the following error

This message is for C/AL programmers: A DotNet variable has not been instantiated. Attempting to call ClosedXML.Excel.IXL.Worksheet.Cell in the Excel Buffer_CloseXML:AddCell

Can anyone help me please.
[-o<

Comments

  • csimoneaux0527csimoneaux0527 Member Posts: 21
    I am using Nav 2013 NOT Nav 2013 R2
  • KerbrusKerbrus Member Posts: 2
    The error msg is very clear.
    This message is for C/AL programmers: A DotNet variable has not been instantiated.
    How to: Call .NET Framework Members from C/AL Code
  • manisharma31manisharma31 Member Posts: 285
    You need to check the dot net variable is created first before writing in the cell.
    Regards,
    Manish
  • csimoneaux0527csimoneaux0527 Member Posts: 21
    I do not understand what it means by "Not Instantiated" The message is not clear to me.
    I am a beginner in the DotNet world. I am asking for help.
    I did create the variable before writing the code.
    How does one check the dot net variable is created first? I read the How To Call.Net but I do not understand it.
    Normally I am not that dumb. the light bulb is just not coming on.
    Please help.
    [-o<

    On The How To...
    I listed my code in the original post

    MyVariableName.ConstructorName(arguments);

    XlWrkShtDotNet.Cell(GlobalRowNo,GlobalColumnNo).Style.Font.Bold := IsBold;

    Variable –
    Name DataType Subtype
    XlWrkShtDotNet DotNet ClosedXML.Excel.IXLWorksheet.'ClosedXML, Version=0.59.0.0,
    Culture=neutral, PublicKeyToken=fd1eb21b62ae805b'

    When I used the C/AL Symbol Menu There was no Constructor listed. But the code did complie
    I know I have missed something but I do not know what it is.
  • aniishaniish Member Posts: 27
    Hi,
    you may instantiate your dotnet variable like following:-
    XMLWhiteCharCheck := XMLWhiteCharCheck.XMLCharWhiteList;
    XlWrkBkDotNet := XlWrkBkDotNet.XLWorkbook();
    you also refer following link for the same issue:-
    http://www.dynamics.is/?p=706
Sign In or Register to comment.