Dear POI Dev team, Currently, I have to edit the .doc file based on the template but after I added more text into the paragraph inside and outside of table in the .doc file but after the file is save by java code I cannot open it in MS Word editor. I am using the "poi-scratchpad-3.2-FINAL-20081019.jar", but I just copy the template to another file and I am able to open it fine. Here is my code: HWPFDocument doc = new HWPFDocument(new FileInputStream(request.getRealPath("/")+"/docs/filename.doc")); Range range = doc.getRange(); for (int x = 0; x < range.numSections(); x++) { Section section = range.getSection(x); int numberOfParagraphs = section.numParagraphs(); boolean inTable = false; boolean rowStart = true; boolean prcessinrow = false; Table table = null; CharacterProperties prop = null; int pos = 0; for (int paragraphIndex = 0; paragraphIndex < numberOfParagraphs; paragraphIndex++) { Paragraph paragraph = null; try { paragraph = section.getParagraph(paragraphIndex); } catch (Exception exception) { System.out.print("Ignore paragraph exception: " + exception.toString()); } if (paragraph != null) { if(paragraphIndex==7){ if (bulletinForm.getBulletinDate()!=null){ prop = new CharacterProperties(); prop.setBold(true); DateFormat formatMMDDYYYY = new SimpleDateFormat("MMMM dd, yyyy"); String bullDate = formatMMDDYYYY.format(newDate); paragraph.insertBefore(bullDate + " Volume "+bulletinForm.getBulletinVolume()+", Number "+bulletinForm.getBulletinNumber(), prop); } } if(paragraphIndex==19){ if (bulletinForm.getBulletinDate()!=null){ prop = new CharacterProperties(); prop.setBold(true); prop.setFontSize(20); DateFormat formatMMDDYYYY = new SimpleDateFormat("MMMM dd, yyyy"); String bullDate = formatMMDDYYYY.format(newDate); paragraph.insertAfter(bullDate, prop); } } if (paragraph.isInTable()) { System.out.print("is in table **"); pos++; if (!inTable) { inTable = true; rowStart = true; } } else { inTable = false; rowStart = false; table = null; pos = 0; System.out.print("End of Table"); } prop = new CharacterProperties(); prop.setBold(true); if (inTable && !paragraph.isTableRowEnd()) { if(pos==7){ paragraph.insertAfter("$1245,458",prop); }else if(pos == 8){ paragraph.insertAfter("$7657576.6565",prop); }else if(pos == 9){ paragraph.insertAfter("$9099976.6565", prop); }else if(pos == 10){ paragraph.insertAfter("10"); } } } } } // Write the result doc to output file FileOutputStream fileOut = new FileOutputStream(request.getRealPath("/")+"/docs/filename1.doc"); doc.write(fileOut); fileOut.flush(); fileOut.close(); Please give me an advise. Thanks and Regards, Lam Duong
Lam Duong, We did some work around POI code related to Word tables. You need to check if problem is still reproducable using POI code from SVN trunk. If it is - please provide an example of filename.doc. -- Sergey.
Also see this on Mac OS X, Windows 7, non-os specific
Please disregard last comment, intended for Bug 56890
No update for years after request for testing with latest version of POI, therefore I am closing this as WORKSFORME for now, please reopen this bug with more information if this is still an issue for you.