Discussion:
Is there a way to set the width of a column in XWPFTableCell?
Bart W Jenkins
2012-11-15 16:30:11 UTC
Permalink
I'm using POI to generate a .docx word file using OOXML and am having trouble figuring out how to set the width of an individual column in a table. Can someone help?

Bart
Yegor Kozlov
2012-11-16 10:12:41 UTC
Permalink
XWPFDocument doc = new XWPFDocument();

//column width in Twentieths of a Point
int[] cols = {2000, 2000, 2000};
XWPFTable table = doc.createTable(3, 3);
for(int i = 0; i < table.getNumberOfRows(); i++){
XWPFTableRow row = table.getRow(i);
int numCells = row.getTableCells().size();
for(int j = 0; j < numCells; j++){
XWPFTableCell cell = row.getCell(j);

cell.getCTTc().addNewTcPr().addNewTcW().setW(BigInteger.valueOf(cols[j]));
}
}


Yegor
Post by Bart W Jenkins
I'm using POI to generate a .docx word file using OOXML and am having trouble figuring out how to set the width of an individual column in a table. Can someone help?
Bart
Bart W Jenkins
2012-11-16 15:53:41 UTC
Permalink
I'll give this a try!

СпасОбП
Post by Yegor Kozlov
XWPFDocument doc = new XWPFDocument();
//column width in Twentieths of a Point
int[] cols = {2000, 2000, 2000};
XWPFTable table = doc.createTable(3, 3);
for(int i = 0; i < table.getNumberOfRows(); i++){
XWPFTableRow row = table.getRow(i);
int numCells = row.getTableCells().size();
for(int j = 0; j < numCells; j++){
XWPFTableCell cell = row.getCell(j);
cell.getCTTc().addNewTcPr().addNewTcW().setW(BigInteger.valueOf(cols[j]));
}
}
Yegor
Post by Bart W Jenkins
I'm using POI to generate a .docx word file using OOXML and am having trouble figuring out how to set the width of an individual column in a table. Can someone help?
Bart
---------------------------------------------------------------------
Bart W Jenkins
2012-11-16 16:05:14 UTC
Permalink
Yegor,
Thank you for the code, but this did NOT work for me. Can you tell me what version of POI you are using? I have 3.8. With this code I get a 3 x 3 table with the column widths set as if they were nearly 0! No matter what I set for the col sizes, the col sizes are not working.

Bart
Post by Yegor Kozlov
XWPFDocument doc = new XWPFDocument();
//column width in Twentieths of a Point
int[] cols = {2000, 2000, 2000};
XWPFTable table = doc.createTable(3, 3);
for(int i = 0; i < table.getNumberOfRows(); i++){
XWPFTableRow row = table.getRow(i);
int numCells = row.getTableCells().size();
for(int j = 0; j < numCells; j++){
XWPFTableCell cell = row.getCell(j);
cell.getCTTc().addNewTcPr().addNewTcW().setW(BigInteger.valueOf(cols[j]));
}
}
Yegor Kozlov
2012-11-16 16:30:39 UTC
Permalink
I'm using the latest build from trunk and Office 2010.
The link to daily builds is on http://poi.apache.org/
Post by Bart W Jenkins
Yegor,
Thank you for the code, but this did NOT work for me. Can you tell me
what version of POI you are using? I have 3.8. With this code I get a 3 x
3 table with the column widths set as if they were nearly 0! No matter what
I set for the col sizes, the col sizes are not working.
Bart
XWPFDocument doc = new XWPFDocument();
//column width in Twentieths of a Point
int[] cols = {2000, 2000, 2000};
XWPFTable table = doc.createTable(3, 3);
for(int i = 0; i < table.getNumberOfRows(); i++){
XWPFTableRow row = table.getRow(i);
int numCells = row.getTableCells().size();
for(int j = 0; j < numCells; j++){
XWPFTableCell cell = row.getCell(j);
cell.getCTTc().addNewTcPr().addNewTcW().setW(BigInteger.valueOf(cols[j]));
}
}
Bart W Jenkins
2012-11-16 17:06:31 UTC
Permalink
Ok, I'll try the latest trunk build.

Thanks again!
Post by Yegor Kozlov
I'm using the latest build from trunk and Office 2010.
The link to daily builds is on http://poi.apache.org/
Post by Bart W Jenkins
Yegor,
Thank you for the code, but this did NOT work for me. Can you tell me
what version of POI you are using? I have 3.8. With this code I get a 3 x
3 table with the column widths set as if they were nearly 0! No matter what
I set for the col sizes, the col sizes are not working.
Bart
XWPFDocument doc = new XWPFDocument();
//column width in Twentieths of a Point
int[] cols = {2000, 2000, 2000};
XWPFTable table = doc.createTable(3, 3);
for(int i = 0; i < table.getNumberOfRows(); i++){
XWPFTableRow row = table.getRow(i);
int numCells = row.getTableCells().size();
for(int j = 0; j < numCells; j++){
XWPFTableCell cell = row.getCell(j);
cell.getCTTc().addNewTcPr().addNewTcW().setW(BigInteger.valueOf(cols[j]));
}
}
---------------------------------------------------------------------
Bart Jenkins
2013-01-08 17:55:01 UTC
Permalink
Yegor,

I tried POI v 3.9 and still no luck. I am using Windows XP sp 3 with MS-Office 2007. I will try Office 2010.

What operating system are you using? Windows XP (and what service pack) or Windows 7 (or 8)?

Bart
Post by Yegor Kozlov
I'm using the latest build from trunk and Office 2010.
The link to daily builds is on http://poi.apache.org/
Post by Bart W Jenkins
Yegor,
Thank you for the code, but this did NOT work for me. Can you tell me
what version of POI you are using? I have 3.8. With this code I get a 3 x
3 table with the column widths set as if they were nearly 0! No matter what
I set for the col sizes, the col sizes are not working.
Bart
XWPFDocument doc = new XWPFDocument();
//column width in Twentieths of a Point
int[] cols = {2000, 2000, 2000};
XWPFTable table = doc.createTable(3, 3);
for(int i = 0; i < table.getNumberOfRows(); i++){
XWPFTableRow row = table.getRow(i);
int numCells = row.getTableCells().size();
for(int j = 0; j < numCells; j++){
XWPFTableCell cell = row.getCell(j);
cell.getCTTc().addNewTcPr().addNewTcW().setW(BigInteger.valueOf(cols[j]));
}
}
---------------------------------------------------------------------
Bart Jenkins
2013-01-08 22:36:42 UTC
Permalink
Yegor,
Ok, the issue was my environment. I had MS-Office 2007 installed. Once I upgraded to MS-Office 2010, the code below works perfectly.

Thanks for that. I've been unable to solve this issue for months!

Bart
Post by Bart W Jenkins
Yegor,
I tried POI v 3.9 and still no luck. I am using Windows XP sp 3 with MS-Office 2007. I will try Office 2010.
What operating system are you using? Windows XP (and what service pack) or Windows 7 (or 8)?
Bart
Post by Yegor Kozlov
I'm using the latest build from trunk and Office 2010.
The link to daily builds is on http://poi.apache.org/
Post by Bart W Jenkins
Yegor,
Thank you for the code, but this did NOT work for me. Can you tell me
what version of POI you are using? I have 3.8. With this code I get a 3 x
3 table with the column widths set as if they were nearly 0! No matter what
I set for the col sizes, the col sizes are not working.
Bart
XWPFDocument doc = new XWPFDocument();
//column width in Twentieths of a Point
int[] cols = {2000, 2000, 2000};
XWPFTable table = doc.createTable(3, 3);
for(int i = 0; i < table.getNumberOfRows(); i++){
XWPFTableRow row = table.getRow(i);
int numCells = row.getTableCells().size();
for(int j = 0; j < numCells; j++){
XWPFTableCell cell = row.getCell(j);
cell.getCTTc().addNewTcPr().addNewTcW().setW(BigInteger.valueOf(cols[j]));
}
}
---------------------------------------------------------------------
Loading...