I am able to create a table in Apache POI in word ,my table is coming with proper value but what i want i want to decrease the cell size of the column size in the table how to do that ,please help..Here is what i have done upto
XWPFTable table = document.createTable(5,3);
r3.setText("MSH Activity Score Card");
r3.setBold(true);
//creating first row
table.getRow(0).getCell(1).setText("Job ID#");
table.getRow(0).getCell(2).setText("1362");
//creating second row
table.getRow(1).getCell(1).setText("Job Title#");
table.getRow(1).getCell(2).setText("Global Network Architect Consultant");
//creating third row
table.getRow(2).getCell(1).setText("Client");
table.getRow(2).getCell(2).setText("Carnival Corporation");
//creating fourth row
table.getRow(3).getCell(1).setText("Start Date");
table.getRow(3).getCell(2).setText("11/13/2014");
//creating fifth row
table.getRow(4).getCell(1).setText("Days Old");
table.getRow(4).getCell(2).setText("33");
CTTblWidth width = table.getCTTbl().addNewTblPr().addNewTblW();
width.setType(STTblWidth.DXA);
width.setW(BigInteger.valueOf(1500));
I am getting a table with data but i want to minimize the size
But i want this size
First you need to make sure that you've declared the library's imports :
Then it's just like , assuming you want to format
cell-0
onrow-0
:Or put this snippet after creating your last row to format all cells:
*But remember that the width of the cell will always increase to follow the length of the string.
Upon creation of the table, the layout is set to "auto" by default hence the width of the cell will always increase to follow the length of the string. As per OpenXML markup, it look's like
w:tblPr w:tblLayout w:type="auto"
the solution is to set the layout to fixed and set the individual column length
w:tblPr w:tblLayout w:type="fixed"
Here's the poi code for setting table layout:
Here's how to set the individual width:
column length 2880 is measured in twentieths of a point (dxa) or 1/1440 inch which is equal to 2 inches.
In my project i have struggled alot to set column width and i have solved this issue by controlling data in cell.