Add left or right border to excell cell

Hi everyone,

I have a problem with my excel export.

I am generating an excel file from a dynamics ax 2009 class. Every 3 column, I want to mark a separation with a border on the right of each cell of the colum. I have a method which add a complete border on the cell (right, left, bottom, top) but I don’t know how to put it on the right only.

Here is my method (which works fine):

public void setBorderToCells(str range)
    SysExcelRange   xlsRange;
    SysExcelStyle   xlsStyle;
    COM             comObject;

    xlsRange  = worksheet.range(range);
    comObject = xlsRange.comObject();
    comObject = comObject.borders();

I also tried this code found on the internet but when I execute it, Dynamics crash and I have the error message “Dynamics Ax stopped working”.

cell = cells.item(row, col);
cellCOM = cell.comObject();; // 4 = right border
borders = cellCOM.borders();
border = borders.item(borderType);;

What can I do?

Thank you in advance.

borders() returns an array of borders and you can access individual borders by their index.

This is how it can be done through .NET API:

// using Microsoft.Office.Interop.Excel;

borders[XlBordersIndex.xlEdgeLeft].LineStyle = XlLineStyle.xlContinuous;

You’ll just have to figure out the right syntax when doing it through for COM objects in X++.

Thank you for the answer.

Also, do you know how I can resize the height of an entire row?

Thank you in advance.