https://issues.apache.org/bugzilla/show_bug.cgi?id=47217
Summary: Cannot open .doc file after adding more text into the
document and table
Product: POI
Version: unspecified
Platform: PC
OS/Version: Windows XP
Status: NEW
Severity: normal
Priority: P2
Component: HWPF
AssignedTo: [email protected]
ReportedBy: [email protected]
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
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]