Dear All
i have ms word document that's contains table, i try to modify the text in
that table using Appache API, but after processing the file become corrupted
, is ther any idea plz?
here is the code
public void testWriter (){
FileInputStream fis;
try {
fis = new FileInputStream("c:
jaber.doc";);
HWPFDocument doc = new HWPFDocument(fis);
Range range = doc.getRange();
int parNum = range.numParagraphs();
Paragraph par;
Table table;
for (int i = 0; i<parNum;i++){
try{
par = range.getParagraph(i);
table = range.getTable(par);
for(int j =0; j< table.numRows(); j ++) {
for(int k=0;k <table.getRow(j).numCells();k++){
// all the table already have some text... which "11"
table.getRow(j).getCell(k).replaceText("1", "jaber");
System.out.println(cellText);
}
}
}
catch(IllegalArgumentException ex){
continue;
}
}
OutputStream out = new FileOutputStream(new File("c:
jaber.doc";));
// am also try to save it to another document file ,,, but i have the same
problem like below
// OutputStream out = new FileOutputStream(new File("c:
jaber2.doc";));
doc.write(out);
out.flush();
out.close();
} catch (FileNotFoundException e) {
} catch (IOException e) {
System.out.println(e.getMessage());
}
}// testWriter methode
thanx in advance
--
View this message in context:
http://apache-poi.1045710.n5.nabble.com/Write-to-table-MS-Word-Document-tp3258766p3258766.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]