`
yanghongxia9
  • 浏览: 112578 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

读取DOC的表

阅读更多
/**
* 读取doc的表格数据
* @param docPath
*/
public static void readDocTable(String docPath){
try {
FileInputStream in = new FileInputStream(docPath);
HWPFDocument hwpf = new HWPFDocument(in);//载入文档
Range range = hwpf.getRange();//得到文档读取范围
TableIterator iterator = new TableIterator(range);
//迭代文档中的表格
while(iterator.hasNext()){
Table table = iterator.next();
System.out.println("===========Table");
//迭代行,默认从0开始
for(int row = 0; row < table.numRows(); row ++){
System.out.println("===Table Row=" + row);
TableRow tableRow = table.getRow(row);
//迭代列,默认从0开始
for(int colum = 0; colum <tableRow.numCells(); colum ++){
TableCell tableCell = tableRow.getCell(colum);
//取得单元格的内容
for(int cell = 0; cell < tableCell.numParagraphs(); cell ++){
org.apache.poi.hwpf.usermodel.Paragraph paragraph = tableCell.getParagraph(cell);
String text = paragraph.text();
System.out.println("Table colum=" + colum + ",text=" + text);
}
}
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics