Package org.apache.poi.hwpf.usermodel

Examples of org.apache.poi.hwpf.usermodel.Range


  {

    try
    {
      HWPFDocument doc = new HWPFDocument(new FileInputStream(args[0]));
      Range r = doc.getRange();
      String str = r.text();
      int x = 0;
//      CharacterRun run = new CharacterRun();
//      run.setBold(true);
//      run.setItalic(true);
//      run.setCapitalized(true);
View Full Code Here


    * TODO - Make this work with 3+ runs
    */
  public void testContents() {
      HWPFDocument doc = docAscii;
      for(int run=0; run<3; run++) {
       Range r;
  
       // Now check the real ranges
       r = doc.getRange();
       assertEquals(
           a_page_1 +
           page_break + "\r" +
           a_page_2,
           r.text()
       );
  
       r = doc.getHeaderStoryRange();
       assertEquals(
           headerDef +
           a_header +
           footerDef +
           a_footer +
           endHeaderFooter,
           r.text()
       );
  
       r = doc.getOverallRange();
       assertEquals(
           a_page_1 +
           page_break + "\r" +
           a_page_2 +
           headerDef +
           a_header +
           footerDef +
           a_footer +
           endHeaderFooter +
           "\r",
           r.text()
       );
        
         // Write out and read back in again, ready for
         //  the next run of the test
         // TODO run more than once
View Full Code Here

            doc = HWPFTestDataSamples.writeOutAndReadBack(doc);
      }
  }

  public void testContentsUnicode() {
    Range r;

    // Now check the real ranges
    r = docUnicode.getRange();
    assertEquals(
        u_page_1 +
        page_break + "\r" +
        u_page_2,
        r.text()
    );

    r = docUnicode.getHeaderStoryRange();
    assertEquals(
        headerDef +
        u_header +
        footerDef +
        u_footer +
        endHeaderFooter,
        r.text()
    );

    r = docUnicode.getOverallRange();
    assertEquals(
        u_page_1 +
        page_break + "\r" +
        u_page_2 +
        headerDef +
        u_header +
        footerDef +
        u_footer +
        endHeaderFooter +
        "\r",
        r.text()
    );
  }
View Full Code Here

  private static String runExtract(String sampleName) {
    HWPFDocument doc = HWPFTestDataSamples.openSampleFile(sampleName);
    StringBuffer out = new StringBuffer();

    Range globalRange = doc.getRange();
    for (int i = 0; i < globalRange.numParagraphs(); i++) {
      Paragraph p = globalRange.getParagraph(i);
      out.append(p.text());
      out.append("\n");
      for (int j = 0; j < p.numCharacterRuns(); j++) {
        CharacterRun characterRun = p.getCharacterRun(j);
        characterRun.text();
View Full Code Here

  /**
   * Test model based extraction
   */
  public void testExtractFromModel() {
    Range r = doc.getRange();

    String[] text = new String[r.numParagraphs()];
    for (int i = 0; i < r.numParagraphs(); i++) {
      Paragraph p = r.getParagraph(i);
      text[i] = p.text();
    }

    assertEquals(p_text.length, text.length);
    for (int i = 0; i < p_text.length; i++) {
View Full Code Here

        testInnerTable( hwpfDocument );
    }

    private void testInnerTable( HWPFDocument hwpfDocument )
    {
        Range range = hwpfDocument.getRange();
        for ( int p = 0; p < range.numParagraphs(); p++ )
        {
            Paragraph paragraph = range.getParagraph( p );
            char first = paragraph.text().toLowerCase().charAt( 0 );
            if ( '1' <= first && first < '4' )
            {
                assertTrue( paragraph.isInTable() );
                assertEquals( 2, paragraph.getTableLevel() );
View Full Code Here

  /**
   * Test model based extraction
   */
  public void testExtractFromModel() {
    Range r = doc.getRange();

    String[] text = new String[r.numParagraphs()];
    for (int i = 0; i < r.numParagraphs(); i++) {
      Paragraph p = r.getParagraph(i);
      text[i] = p.text();
    }

    assertEquals(p_text.length, text.length);
    for (int i = 0; i < p_text.length; i++) {
View Full Code Here

    * TODO - Make this work with 3+ runs
    */
  public void testContents() {
      HWPFDocument doc = docAscii;
      for(int run=0; run<3; run++) {
       Range r;
  
       // Now check the real ranges
       r = doc.getRange();
       assertEquals(
           a_page_1 +
           page_break + "\r" +
           a_page_2,
           r.text()
       );
  
       r = doc.getHeaderStoryRange();
       assertEquals(
           headerDef +
           a_header +
           footerDef +
           a_footer +
           endHeaderFooter,
           r.text()
       );
  
       r = doc.getOverallRange();
       assertEquals(
           a_page_1 +
           page_break + "\r" +
           a_page_2 +
           headerDef +
           a_header +
           footerDef +
           a_footer +
           endHeaderFooter +
           "\r",
           r.text()
       );
        
         // Write out and read back in again, ready for
         //  the next run of the test
         // TODO run more than once
View Full Code Here

            doc = HWPFTestDataSamples.writeOutAndReadBack(doc);
      }
  }

  public void testContentsUnicode() {
    Range r;

    // Now check the real ranges
    r = docUnicode.getRange();
    assertEquals(
        u_page_1 +
        page_break + "\r" +
        u_page_2,
        r.text()
    );

    r = docUnicode.getHeaderStoryRange();
    assertEquals(
        headerDef +
        u_header +
        footerDef +
        u_footer +
        endHeaderFooter,
        r.text()
    );

    r = docUnicode.getOverallRange();
    assertEquals(
        u_page_1 +
        page_break + "\r" +
        u_page_2 +
        headerDef +
        u_header +
        footerDef +
        u_footer +
        endHeaderFooter +
        "\r",
        r.text()
    );
  }
View Full Code Here

  public String[] getParagraphText() {
      String[] ret;

      // Extract using the model code
      try {
          Range r = doc.getRange();

          ret = WordExtractor.getParagraphText(r);
      } catch (Exception e) {
            // Something's up with turning the text pieces into paragraphs
            // Fall back to ripping out the text pieces
View Full Code Here

TOP

Related Classes of org.apache.poi.hwpf.usermodel.Range

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.