XWPFTable: how to set column width and cell borders?

Jan 28, 2015 at 12:30 PM
Edited Jan 28, 2015 at 2:13 PM
Hello,
I have just begun creating docx with XWPFDocument. Could you please advice if my approach is proper, assuming that I would like to create a table with 3 columns, first narrow, second and third wider:
XWPFTable t0 = doc.CreateTable( 3, 3 );
t0.Width = 5000;

t0.GetRow( 0 ).GetCell( 0 ).SetText( "A" );
t0.GetRow( 0 ).GetCell( 1 ).SetText( "B" );
t0.GetRow( 0 ).GetCell( 2 ).SetText( "C" );

t0.GetRow( 1 ).GetCell( 0 ).SetText( "X" );
t0.GetRow( 1 ).GetCell( 1 ).SetText( "Name 1, Name 2, Name 3, Name 4" );
t0.GetRow( 1 ).GetCell( 2 ).SetText( "Name 1, Name 2, Name 3, Name 4" );

t0.SetColumnWidth( 0, 1000 );
t0.SetColumnWidth( 1, 2000 );
t0.SetColumnWidth( 2, 2000 );
Beside of it I would like to leave only horizontal lines (top, bottom and innern) for the table.
I know how to modify presence of cell borders for a spreadsheet but not for the Word docx table. Here I tried for the [0, 0] cell something like:
XWPFTableCell c00 = t0.GetRow( 0 ).GetCell( 0 );
CT_TcBorders c00Borders = c00.GetCTTc( ).AddNewTcPr( ).AddNewTcBorders( );
c00Borders.left = new CT_Border { val = ST_Border.nil };
c00Borders.right = new CT_Border { val = ST_Border.nil };
c00Borders.insideV = new CT_Border { val = ST_Border.nil };
but I am not sure if that is proper. Any help if I may please?