1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
public static void main( String[] args )
{
String filesname = "../CASPER/Img/test.rtf";
POIFSFileSystem fs = null;
try
{
fs = new POIFSFileSystem(new FileInputStream(filesname));
HWPFDocument doc = new HWPFDocument(fs);
Range range = doc.getRange();
for (int i = 0; i < range.numSections(); i++)
{
Section section = range.getSection(i);
for (int x = 0; x < section.numParagraphs(); x++)
{
Paragraph p = section.getParagraph(x);
for (int z = 0; z < p.numCharacterRuns(); z++)
{
//character run
CharacterRun run = p.getCharacterRun(z);
//character run text
String text = run.text();
if( text.contains("DEMANDE"))
{
run.insertAfter("Eulu");
}
}
}
}
OutputStream out = new FileOutputStream(new File("../CASPER/Img/sample2.dot"));
doc.write(out);
out.flush();
out.close();
// WordExtractor we = new WordExtractor(doc);
// String[] paragraphs = we.getParagraphText();
//
// System.out.println( "Word Document has " + paragraphs.length + " paragraphs" );
// for( int i=0; i<paragraphs .length; i++ ) {
// paragraphs[i] = paragraphs[i].replaceAll("\\cM?\r?\n","");
// System.out.println( "Length:"+paragraphs[ i ]);
// }
}
catch(Exception e)
{
e.printStackTrace();
}
} |
Partager