Results 1 to 5 of 5
- 11-22-2012, 12:19 PM #1
Member
- Join Date
- Nov 2012
- Posts
- 5
- Rep Power
- 0
Writing a table without a Border to Word with Poi
Hello :-)
I will write a table to Word with the framework poi.
From another webside I found an example of this. But unfortunately I don't know how to remove the border of the table.
Did anyone have an idea?
Best regards,
louisa.
Java Code:public static void main(String[] args) throws Exception { XWPFDocument document = new XWPFDocument(); // Create a new table with 6 rows and 3 columns int nRows = 2; int nCols = 5; XWPFTable table = document.createTable(nRows, nCols); CTTblPr tablePr = table.getCTTbl().getTblPr(); CTString styleTable = tablePr.addNewTblStyle(); styleTable.setVal("meinStyle"); // Get a list of the rows in the table List<XWPFTableRow> rows = table.getRows(); int rowCt = 0; int colCt = 0; // ueber die Zeilen iterieren for (XWPFTableRow row : rows) { CTTrPr rowProperties = row.getCtRow().addNewTrPr(); CTHeight rowHeight = rowProperties.addNewTrHeight(); rowHeight.setVal(BigInteger.valueOf(360)); // get the cells in this row List<XWPFTableCell> cells = row.getTableCells(); // iteriere ueber die Zellen for (XWPFTableCell cell : cells) { CTTcPr cellPropertie = cell.getCTTc().addNewTcPr(); CTVerticalJc verticalCell = cellPropertie.addNewVAlign(); verticalCell.setVal(STVerticalJc.CENTER); CTShd ctshd = cellPropertie.addNewShd(); ctshd.setColor("auto"); ctshd.setVal(STShd.CLEAR); if (rowCt == 0) { // header row ctshd.setFill("A7BFDE"); } else if (rowCt % 2 == 0) { // even row ctshd.setFill("D3DFEE"); } else { // odd row ctshd.setFill("EDF2F8"); } // get 1st paragraph in cell's paragraph list XWPFParagraph para = cell.getParagraphs().get(0); XWPFRun rh = para.createRun(); // style cell as desired rh.setFontSize(5); rh.setFontFamily("Courier"); para.setAlignment(ParagraphAlignment.CENTER); if (rowCt == 0) { // header row rh.setText("header row, col " + colCt); } else if (rowCt % 2 == 0) { // even row rh.setText("row " + rowCt + ", col " + colCt); } else { // odd row rh.setText("row " + rowCt + ", col " + colCt); } colCt++; } // for cell colCt = 0; rowCt++; } // for row // write the file FileOutputStream out = new FileOutputStream("D:/styledTable1.doc"); document.write(out); out.close(); }
- 11-22-2012, 02:03 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Writing a table without a Border to Word with Poi
XWPFTable has some methods that deal with border types.
Please do not ask for code as refusal often offends.
- 11-22-2012, 02:09 PM #3
Member
- Join Date
- Nov 2012
- Posts
- 5
- Rep Power
- 0
Re: Writing a table without a Border to Word with Poi
thats true. I try it with the following in Row 51:
But it doesnt work, I still see the borders in the word documentpara.setBorderBottom(Borders.NONE);
para.setBorderLeft(Borders.NONE);
para.setBorderRight(Borders.NONE);
para.setBorderTop(Borders.NONE);
- 11-22-2012, 02:23 PM #4
Member
- Join Date
- Nov 2012
- Posts
- 5
- Rep Power
- 0
Re: Writing a table without a Border to Word with Poi
Very good, now I paste only this Rows to my programm:
But the border outside are still there. Only the bordes outside are hidden.Java Code:XWPFTable table = document.createTable(nRows, nCols); table.setInsideHBorder(XWPFBorderType.NONE, 10, 5, "1C7331"); table.setInsideVBorder(XWPFBorderType.NONE, 10, 5, "1C7331");
So I search for this solution....
Thank you....
- 11-23-2012, 04:09 PM #5
Member
- Join Date
- Nov 2012
- Posts
- 5
- Rep Power
- 0
Re: Writing a table without a Border to Word with Poi
Here is my solution. I use a window document which Iam import to my programm. This Word-Document already have an empty table without border and fill it in the programm:
Java Code:private void adText2Table(XWPFDocument doc, String text, int row, int cell, int tableIdx) { XWPFTableRow xWPFTableRow; XWPFTable table = doc.getTables().get(tableIdx); List<XWPFTableRow> zeile = table.getRows(); if (zeile.size() >= row + 1) { xWPFTableRow = zeile.get(row); } else { xWPFTableRow = doc.getTables().get(tableIdx).createRow(); } xWPFTableRow.getCell(cell).setText(text); }
Similar Threads
-
Find a text in a file and write a word following this word
By lemontree45 in forum New To JavaReplies: 3Last Post: 08-30-2011, 04:44 PM -
writing word document using poi hwpf
By devday in forum New To JavaReplies: 4Last Post: 08-07-2011, 11:15 AM -
create word doucment with Table of contents(TOC)
By jagadeeshkasa in forum Forum GuidesReplies: 0Last Post: 02-04-2011, 05:50 AM -
How to create a table in word document using hwpf
By devday in forum Advanced JavaReplies: 0Last Post: 07-23-2009, 02:41 PM -
Reading Writing to Microsoft Word -Urgent
By Robert_85 in forum Advanced JavaReplies: 5Last Post: 04-13-2009, 12:20 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks