Export Data to Excel using closedXml


I want to Export the data to excel using closedxml.I have add the closedxml dll to Aot reference and I have written below sample code to export to excel but I am getting error like “Variable ClosedXml has not been declared.”.How to resolve the error.

ClosedXml.Excel.XLWorkbook workbook;
ClosedXml.Excel.IXLWorksheet worksheet;
ClosedXml.Excel.IXLCell cell;

workbook = new ClosedXml.Excel.XLWorkbook();
worksheet = workbook.addworksheet(“s1”);
cell = worksheet.Cell(“A1”);
cell = worksheet.Cell(“A2”);

Please don’t forget to tag your AX version.
See this, msdn.microsoft.com/…/cc586538.aspx

You didn’t mention installing the ClosedXml library. Maybe you didn’t do it right.

Thanks for both of your help.now Excel is opening.

how to color the rows and columns uisng closedxml.
Ex: i want red color to cell of row =2,col = 2.
How to achieve it using closedxml

Have you seen the documentation?

I want to set color for cell like (2,2)


I tried this one error is showing in XLColor line like “Syntax error” for line 2nd and 3rd line.can you suggest me.
customer.Rows(Row, col).Style.Fill.BackgroundColor = XLColor.Blue;

customer1.Cell(Row, 1).Style.Fill.BackgroundColor = XLColor.Red;

customer1.Cell(Row, 2).Value = “XLColor.Red”;

For the 4th line i getting error like table out of range or does not exist.

The same syntax may not work in AX. See if the BackgroundColor takes the value as parameter

Yes…but in ax there is no such parameter supported for background().
Ex:customer1.Cell(Row, 1).Style.Fill.BackgroundColor.value( XLColor.Red);
I think above link is not ax code.Can you tell what method is supported for the background color using closedxml.

customer1.Cell(Row, 1). → do you see Style by using intelliSence?
I mean this, BackgroundColor( XLColor.Red);

I am not getting any intellisense for customer.Cell(Row, 1).,same syntax error is coming for the line customer1.Cell(Row, 1).Style.Fill.BackgroundColor(XLColor.Blue);

ClosedXml.Excel.IXLCell , what methods do you have in this?
I haven’t used closedXML before or neither i have it in my environment. You should read the document of it, to know what methods it offers and see how to access its classes and members,