KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hwpf > QuickTest


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        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 {
26   public QuickTest()
27   {
28   }
29
30   public static void main(String JavaDoc[] args)
31   {
32     try
33     {
34       HWPFDocument doc = new HWPFDocument (new FileInputStream (args[0]));
35       Range r = doc.getRange();
36
37       System.out.println("Example you supplied:");
38       System.out.println("---------------------");
39       for (int x = 0; x < r.numSections(); x++)
40       {
41         Section s = r.getSection(x);
42         for (int y = 0; y < s.numParagraphs(); y++)
43         {
44           Paragraph p = s.getParagraph(y);
45           for (int z = 0; z < p.numCharacterRuns(); z++)
46           {
47             //character run
48
CharacterRun run = p.getCharacterRun(z);
49             //character run text
50
String JavaDoc text = run.text();
51             // show us the text
52
System.out.print(text);
53           }
54           // use a new line at the paragraph break
55
System.out.println();
56         }
57       }
58
59
60 // System.out.println("\n\nExample using new method:");
61
// System.out.println("-------------------------");
62
// for (int x = 0; x < r.numSections(); x++)
63
// {
64
// Section s = r.getSection(x);
65
// for (int y = 0; y < s.numParagraphs(); y++)
66
// {
67
// Paragraph p = s.getParagraph(y);
68
// for (int z = 0; z < p.numCharacterRuns(); z++)
69
// {
70
// //character run
71
// CharacterRun run = p.getCharacterRun(z);
72
// //** get character run/paragraph common text **
73
// String text = run.commonText(p);
74
// // show us the text
75
// System.out.print(text);
76
// }
77
// // use a new line at the paragraph break
78
// System.out.println();
79
// }
80
// }
81

82     }
83     catch (Throwable JavaDoc t)
84     {
85       t.printStackTrace();
86     }
87   }
88
89 }
90
Popular Tags