user198003 user198003 - 3 months ago 36
C# Question

Tables and cells in Word document created by C# - how to change color of only one border?

I have MS Word document with table in it, all created by C#. Problem I have is how to change border color only between two cells, and not to change of whole table? Is it possible to do?

Word document is created on "usual" way, as described here.

Can you help me with this?

UPDATE: Word document and tables are created using next article:


Not sure that I selected the proper table but here is the idea:

    oTable.Cell(0, 0).Select(); //select the cell
//set up the left, right and top borders invisible (may be you don't need to do that)
            oTable.Range.Borders[WdBorderType.wdBorderLeft].LineStyle = WdLineStyle.wdLineStyleNone;
            oTable.Range.Borders[WdBorderType.wdBorderRight].LineStyle = WdLineStyle.wdLineStyleNone;
            oTable.Range.Borders[WdBorderType.wdBorderTop].LineStyle = WdLineStyle.wdLineStyleNone;

//set up the bottom border blue
            oTable.Range.Borders[WdBorderType.wdBorderBottom].LineStyle = WdLineStyle.wdLineStyleSingle;
            oTable.Range.Borders[WdBorderType.wdBorderBottom].LineWidth = WdLineWidth.wdLineWidth050pt;
            oTable.Range.Borders[WdBorderType.wdBorderBottom].Color = WdColor.wdColorBlue;

Usually if I want to do something and I don't know how to do that just open office program (Word in your case), start macro, do something, record and then see the generated code. Usually it would be enough to understand how to implement it.