Package org.apache.poi.hwpf

Examples of org.apache.poi.hwpf.HWPFDocument


     * [RESOLVED FIXED] Bug 48065 - Problems with save output of HWPF (losing
     * formatting)
     */
    public void test48065()
    {
        HWPFDocument doc1 = HWPFTestDataSamples.openSampleFile( "Bug48065.doc" );
        HWPFDocument doc2 = HWPFTestDataSamples.writeOutAndReadBack( doc1 );

        Range expected = doc1.getRange();
        Range actual = doc2.getRange();

        assertEquals(
                expected.text().replace( "\r", "\n" ).replaceAll( "\n\n", "\n" ),
                actual.text().replace( "\r", "\n" ).replaceAll( "\n\n", "\n" ) );

View Full Code Here


    /**
     * Bug 50936 - Exception parsing MS Word 8.0 file
     */
    public void test50936_1()
    {
        HWPFDocument hwpfDocument = HWPFTestDataSamples
                .openSampleFile( "Bug50936_1.doc" );
        hwpfDocument.getPicturesTable().getAllPictures();
    }
View Full Code Here

    /**
     * Bug 50936 - Exception parsing MS Word 8.0 file
     */
    public void test50936_2()
    {
        HWPFDocument hwpfDocument = HWPFTestDataSamples
                .openSampleFile( "Bug50936_2.doc" );
        hwpfDocument.getPicturesTable().getAllPictures();
    }
View Full Code Here

    /**
     * Bug 50936 - Exception parsing MS Word 8.0 file
     */
    public void test50936_3()
    {
        HWPFDocument hwpfDocument = HWPFTestDataSamples
                .openSampleFile( "Bug50936_3.doc" );
        hwpfDocument.getPicturesTable().getAllPictures();
    }
View Full Code Here

     * [RESOLVED FIXED] Bug 51604 - replace text fails for doc ( poi 3.8 beta
     * release from download site )
     */
    public void test51604()
    {
        HWPFDocument document = HWPFTestDataSamples
                .openSampleFile( "Bug51604.doc" );

        Range range = document.getRange();
        int numParagraph = range.numParagraphs();
        int counter = 0;
        for ( int i = 0; i < numParagraph; i++ )
        {
            Paragraph paragraph = range.getParagraph( i );
            int numCharRuns = paragraph.numCharacterRuns();
            for ( int j = 0; j < numCharRuns; j++ )
            {
                CharacterRun charRun = paragraph.getCharacterRun( j );
                String text = charRun.text();
                charRun.replaceText( text, "+" + ( ++counter ) );
            }
        }

        document = HWPFTestDataSamples.writeOutAndReadBack( document );
        String text = document.getDocumentText();
        assertEquals( "+1+2+3+4+5+6+7+8+9+10+11+12", text );
    }
View Full Code Here

     * @throws IOException
     * @throws FileNotFoundException
     */
    public void test51604p2() throws Exception
    {
        HWPFDocument doc = HWPFTestDataSamples.openSampleFile( "Bug51604.doc" );

        Range range = doc.getRange();
        int numParagraph = range.numParagraphs();
        for ( int i = 0; i < numParagraph; i++ )
        {
            Paragraph paragraph = range.getParagraph( i );
            int numCharRuns = paragraph.numCharacterRuns();
            for ( int j = 0; j < numCharRuns; j++ )
            {
                CharacterRun charRun = paragraph.getCharacterRun( j );
                String text = charRun.text();
                if ( text.contains( "Header" ) )
                    charRun.replaceText( text, "added" );
            }
        }

        doc = HWPFTestDataSamples.writeOutAndReadBack( doc );
        final FileInformationBlock fileInformationBlock = doc
                .getFileInformationBlock();

        int totalLength = 0;
        for ( SubdocumentType type : SubdocumentType.values() )
        {
            final int partLength = fileInformationBlock
                    .getSubdocumentTextStreamLength( type );
            assert ( partLength >= 0 );

            totalLength += partLength;
        }
        assertEquals( doc.getText().length(), totalLength );
    }
View Full Code Here

     * [RESOLVED FIXED] Bug 51604 - replace text fails for doc ( poi 3.8 beta
     * release from download site )
     */
    public void test51604p3() throws Exception
    {
        HWPFDocument doc = HWPFTestDataSamples.openSampleFile( "Bug51604.doc" );

        byte[] originalData = new byte[doc.getFileInformationBlock()
                .getLcbDop()];
        System.arraycopy( doc.getTableStream(), doc.getFileInformationBlock()
                .getFcDop(), originalData, 0, originalData.length );

        HWPFOutputStream outputStream = new HWPFOutputStream();
        doc.getDocProperties().writeTo( outputStream );
        final byte[] oldData = outputStream.toByteArray();

        assertEquals( Arrays.toString( originalData ),
                Arrays.toString( oldData ) );

        Range range = doc.getRange();
        int numParagraph = range.numParagraphs();
        for ( int i = 0; i < numParagraph; i++ )
        {
            Paragraph paragraph = range.getParagraph( i );
            int numCharRuns = paragraph.numCharacterRuns();
            for ( int j = 0; j < numCharRuns; j++ )
            {
                CharacterRun charRun = paragraph.getCharacterRun( j );
                String text = charRun.text();
                if ( text.contains( "Header" ) )
                    charRun.replaceText( text, "added" );
            }
        }

        doc = HWPFTestDataSamples.writeOutAndReadBack( doc );

        outputStream = new HWPFOutputStream();
        doc.getDocProperties().writeTo( outputStream );
        final byte[] newData = outputStream.toByteArray();

        assertEquals( Arrays.toString( oldData ), Arrays.toString( newData ) );
    }
View Full Code Here

    public void test51671() throws Exception
    {
        InputStream is = POIDataSamples.getDocumentInstance()
                .openResourceAsStream( "empty.doc" );
        NPOIFSFileSystem npoifsFileSystem = new NPOIFSFileSystem( is );
        HWPFDocument hwpfDocument = new HWPFDocument(
                npoifsFileSystem.getRoot() );
        hwpfDocument.write( new ByteArrayOutputStream() );
    }
View Full Code Here

        // set.
        // TODO: refactor into something nicer!
        if ( System.getProperty( "poi.test.remote" ) != null )
        {
            String href = "http://domex.nps.edu/corp/files/govdocs1/007/007488.doc";
            HWPFDocument hwpfDocument = HWPFTestDataSamples
                    .openRemoteFile( href );

            WordExtractor wordExtractor = new WordExtractor( hwpfDocument );
            wordExtractor.getText();
        }
View Full Code Here

     * [FIXED] Bug 51902 - Picture.fillRawImageContent -
     * ArrayIndexOutOfBoundsException
     */
    public void testBug51890()
    {
        HWPFDocument doc = HWPFTestDataSamples.openSampleFile( "Bug51890.doc" );
        for ( Picture picture : doc.getPicturesTable().getAllPictures() )
        {
            PictureType pictureType = picture.suggestPictureType();
            logger.log( POILogger.DEBUG,
                    "Picture at offset " + picture.getStartOffset()
                            + " has type " + pictureType );
View Full Code Here

TOP

Related Classes of org.apache.poi.hwpf.HWPFDocument

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.