Tuesday, March 20, 2012

COMVariant type to work with Excel in AX

To avoid eventual issues while working with Excel objects in X++, do not forget about COMVariant type in AX!

Lets say we output some information directly to an Excel file and want to change the current row height based on the number of strings on notes.

COM             rng;
COMVariant      rowHeightVariant;
real            rowHeight;

rng = wks.Range(strFmt("A%1", curRow));   cell.Value2(_route.OprNum);
// to keep the current row height
rowHeightVariant = rng.RowHeight();
rowHeight = rowHeightVariant.double();
//to adjust the row height accordingly to the number of strings in notes

Unfortunately, I had spent so much time trying to understand the reason of errors until I found this posting. Thank you Max!


Sunil Dharmani said...

Is it possible to merge cells in x++

wojzeh said...

I believe yes if can get access to such a function of the Excel object.

Sunil Dharmani said...

but there is no such method available in x++