2013年12月4日星期三

poi operating word 2007 ( how to delete a word in a table ) to solve

package re.word;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.List;

import org.apache.poi.POIXMLDocument;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
import org.apache.poi.xwpf.usermodel.XWPFTableRow;

public class TRD {
public static void main (String [] args) {

try {
OPCPackage pkg = POIXMLDocument.openPackage ("c: \ \ wordtest.docx");
XWPFDocument doc = new XWPFDocument (pkg);
Iterator it = doc.getTablesIterator ();
while (it.hasNext ()) {
XWPFTable table = it.next ();
List rows = table.getRows ();
for (int i = rows.size (); i> = 0; i -) {
System.out.println ("table.getRows ()" + table.getRows () size ().);
table.removeRow (i);
}

}
FileOutputStream fos = new FileOutputStream ("C: \ \ tes.docx");

doc.write (fos);
fos.flush ();
fos.close ();

} catch (IOException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
}
}

}
I wrote above is deleted word 2007 source code form . The problem is that the table is always a line can not be deleted ( delete 5 lines before deleting the table after table there is a line not deleted ) , seeking to delete the entire table code , thank
------ Solution - -------------------------------------------
sheet.shiftRows ( 1,2, -1)
------ For reference only ------------------------------- --------
give yourself a sofa !
------ For reference only --------------------- ------------------
problem solved .
------ For reference only ------------- --------------------------
you delete the table how to deal with ? Talk . . I have encountered this problem.
------ For reference only -------------------------------------- -
if my word2007 file is uploaded from the browser over it , how to resolve

没有评论:

发表评论