Search code examples
c#word-interop

How do I draw a border on a series of cells using Interop.Word?


I am currently using Interop.Word to draw tables for a document. I am looking to draw only the outside border for a set of cells (e.g. R1C1 to R2C3) I roughly know how to draw a full outside border around one cell.

Any advice is appreciated.

I know I can set the border for a cell by calling the outsidelinestyle code.

I've read somewhere I can manually call the individual borders but that would be my worst case scenario. Word table with borders

Currently what I have for those 1x1 cells is this:

    Word.Cell wrdCell = wdTable.Cell(1, 1);
    wrdCell.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;

I am hoping that I can just call something to draw the border around the range of cells.


Solution

  • Hello Try to rework below code :

    Word.Range range = w_doc.Range(ref missing, ref missing);
    Word.Table myTable = range.Tables.Add(range, numero_de_linhas, numero_de_colunas);
    
    myTable.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
    myTable.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;