01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: ==================================================================== */
17:
18: package org.apache.poi.hwpf;
19:
20: import java.io.*;
21:
22: import org.apache.poi.hwpf.usermodel.*;
23:
24: public class QuickTest {
25: public QuickTest() {
26: }
27:
28: public static void main(String[] args) {
29: try {
30: HWPFDocument doc = new HWPFDocument(new FileInputStream(
31: args[0]));
32: Range r = doc.getRange();
33:
34: System.out.println("Example you supplied:");
35: System.out.println("---------------------");
36: for (int x = 0; x < r.numSections(); x++) {
37: Section s = r.getSection(x);
38: for (int y = 0; y < s.numParagraphs(); y++) {
39: Paragraph p = s.getParagraph(y);
40: for (int z = 0; z < p.numCharacterRuns(); z++) {
41: //character run
42: CharacterRun run = p.getCharacterRun(z);
43: //character run text
44: String text = run.text();
45: // show us the text
46: System.out.print(text);
47: }
48: // use a new line at the paragraph break
49: System.out.println();
50: }
51: }
52:
53: // System.out.println("\n\nExample using new method:");
54: // System.out.println("-------------------------");
55: // for (int x = 0; x < r.numSections(); x++)
56: // {
57: // Section s = r.getSection(x);
58: // for (int y = 0; y < s.numParagraphs(); y++)
59: // {
60: // Paragraph p = s.getParagraph(y);
61: // for (int z = 0; z < p.numCharacterRuns(); z++)
62: // {
63: // //character run
64: // CharacterRun run = p.getCharacterRun(z);
65: // //** get character run/paragraph common text **
66: // String text = run.commonText(p);
67: // // show us the text
68: // System.out.print(text);
69: // }
70: // // use a new line at the paragraph break
71: // System.out.println();
72: // }
73: // }
74:
75: } catch (Throwable t) {
76: t.printStackTrace();
77: }
78: }
79:
80: }
|