Package org.apache.poi.hwpf.usermodel

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


        protected static String[] getParagraphText(Range r) {
                String[] ret;
                ret = new String[r.numParagraphs()];
                for (int i = 0; i < ret.length; i++) {
                        Paragraph p = r.getParagraph(i);
                        ret[i] = p.text();

                        // Fix the line ending
                        if (ret[i].endsWith("\r")) {
                                ret[i] = ret[i] + "\n";
                        }
View Full Code Here


    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();
      }
    }
    return out.toString();
  }
View Full Code Here

  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++) {
      assertEquals(p_text[i], text[i]);
View Full Code Here

    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() );
            }

            if ( 'a' <= first && first < 'z' )
            {
                assertTrue( paragraph.isInTable() );
                assertEquals( 1, paragraph.getTableLevel() );
            }
        }
    }
View Full Code Here

  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++) {
      assertEquals(p_text[i], text[i]);
View Full Code Here

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

            // Fix the line ending
            if ( ret[i].endsWith( "\r" ) )
            {
                ret[i] = ret[i] + "\n";
View Full Code Here

    parProps.setTableLevel((byte)1);

    int columns = props.getItcMac();
    for (int x = 0; x < rows; x++)
    {
      Paragraph cell = this.insertBefore(parProps, StyleSheet.NIL_STYLE);
      cell.insertAfter(String.valueOf('\u0007'));
      for(int y = 1; y < columns; y++)
      {
        cell = cell.insertAfter(parProps, StyleSheet.NIL_STYLE);
        cell.insertAfter(String.valueOf('\u0007'));
      }
      cell = cell.insertAfter(parProps, StyleSheet.NIL_STYLE, String.valueOf('\u0007'));
      cell.setTableRowEnd(props);
    }
    return new Table(_start, _start + (rows * (columns + 1)), this, 1);
  }
View Full Code Here

    try {
        Range r = doc.getRange();

      ret = new String[r.numParagraphs()];
      for(int i=0; i<ret.length; i++) {
        Paragraph p = r.getParagraph(i);
        ret[i] = p.text();
       
        // Fix the line ending
        if(ret[i].endsWith("\r")) {
          ret[i] = ret[i] + "\n";
        }
View Full Code Here

  {
    initParagraphs();
    PAPX papx = (PAPX)_paragraphs.get(index + _parStart);

    ParagraphProperties props = papx.getParagraphProperties(_doc.getStyleSheet());
    Paragraph pap = null;
    if (props.getIlfo() > 0)
    {
      pap = new ListEntry(papx, this, _doc.getListTables());
    }
    else
    {
      pap = new Paragraph(papx, this);
    }

    return pap;
  }
View Full Code Here

                    } else if ("Document".equals(name)) {
                        HWPFDocument doc = new HWPFDocument(data.getData());
                        //read the word document
                        Range r = doc.getRange();     
                        for(int k = 0; k < r.numParagraphs(); k++) {
                            Paragraph p = r.getParagraph(k);
                            System.out.println(p.text());
                         }

                        //save on disk
                        FileOutputStream out = new FileOutputStream(name + "-("+(j)+").doc");
                        doc.write(out);
                        out.close();
                     else {
                        FileOutputStream out = new FileOutputStream(ole.getProgID() + "-"+(j+1)+".dat");
                        InputStream dis = data.getData();
                        byte[] chunk = new byte[2048];
                        int count;
                        while ((count = dis.read(chunk)) >= 0) {
                          out.write(chunk,0,count);
                        }
                        is.close();
                        out.close();
                    }
                }

            }
        }

        //Pictures
        for (int i = 0; i < slide.length; i++) {
            Shape[] shape = slide[i].getShapes();
            for (int j = 0; j < shape.length; j++) {
                if (shape[j] instanceof Picture) {
                    Picture p = (Picture) shape[j];
                    PictureData data = p.getPictureData();
                    String name = p.getPictureName();
                    int type = data.getType();
                    String ext;
                    switch (type) {
                        case Picture.JPEG:
                            ext = ".jpg";
View Full Code Here

TOP

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

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.