poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 53243] New: Extract Tables from word document
Date Wed, 16 May 2012 15:43:34 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=53243

          Priority: P2
            Bug ID: 53243
          Assignee: dev@poi.apache.org
           Summary: Extract Tables from word document
          Severity: normal
    Classification: Unclassified
                OS: Windows XP
          Reporter: ayah683@gmail.com
          Hardware: PC
            Status: NEW
           Version: unspecified
         Component: HWPF
           Product: POI

Created attachment 28793
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=28793&action=edit
word document file

i used POI 3.8 to extract tables from word document
but i can't get all tables in Doc
i write this code to get this action

    public static void main(String[] args) {
        String fileName = "C:\\fjn3312r.doc";
        try {
            InputStream fis = new FileInputStream(fileName);
            POIFSFileSystem fs = new POIFSFileSystem(fis);
            HWPFDocument doc = new HWPFDocument(fs);

            Range range = doc.getRange();

            int tblNameIdx = 0;
            for (int i = 0; i < range.numParagraphs(); i++) {


                Paragraph tablePar = range.getParagraph(i);

                String parText = tablePar.text();

                try {
                    Pattern pattern = Pattern.compile("[\\s]*",
Pattern.CASE_INSENSITIVE);
                    Matcher matcher = pattern.matcher(parText);

                    if (matcher.matches()) {
                        continue;
                    }
matcher.matches());
                } catch (Exception e) {
                    e.printStackTrace();
                }

                    Paragraph tableName = range.getParagraph(tblNameIdx);
                    System.out.println("Table name=====>>" + tableName.text());
                    Table table = range.getTable(tablePar);
                    for (int rowIdx = 0; rowIdx < table.numRows(); rowIdx++) {
                        TableRow row = table.getRow(rowIdx);
                        BorderCode bc = row.getVerticalBorder();
                        i = i + 1;
                        row.text();

                        String rowText = "";
                        for (int colIdx = 0; colIdx < row.numCells(); colIdx++)
{
                            TableCell cell = row.getCell(colIdx);
                            rowText = rowText + "\t" +
cell.getParagraph(0).text();


                            i = i + 1;
                        }
                        System.out.println("Row----" + rowIdx + " ===>>" +
rowText);

                    }
                    i = i - 1;
                } else {
                    tblNameIdx = i;
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

-- 
You are receiving this mail because:
You are the assignee for the bug.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message