Package org.apache.poi.hwpf
Class HWPFDocument
- java.lang.Object
-
- org.apache.poi.POIDocument
-
- org.apache.poi.hwpf.HWPFDocumentCore
-
- org.apache.poi.hwpf.HWPFDocument
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public final class HWPFDocument extends HWPFDocumentCore
This class acts as the bucket that we throw all of the Word data structures into.
-
-
Constructor Summary
Constructors Constructor Description HWPFDocument(java.io.InputStream istream)This constructor loads a Word document from an InputStream.HWPFDocument(DirectoryNode directory)This constructor loads a Word document from a specific point in a POIFSFileSystem, probably not the default.HWPFDocument(POIFSFileSystem pfilesystem)This constructor loads a Word document from a POIFSFileSystem
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description intcharacterLength()Returns the character length of a document.voiddelete(int start, int length)BookmarksgetBookmarks()RangegetCommentsRange()Returns theRangewhich covers all annotations.byte[]getDataStream()DocumentPropertiesgetDocProperties()RangegetEndnoteRange()Returns theRangewhich covers all endnotes.NotesgetEndnotes()EscherRecordHoldergetEscherRecordHolder()FieldsgetFields()Returns user-friendly interface to access documentFieldsFieldsTablesgetFieldsTables()Deprecated.POI 3.8.RangegetFootnoteRange()Returns theRangewhich covers all the Footnotes.NotesgetFootnotes()RangegetHeaderStoryRange()Returns the range which covers all "Header Stories".RangegetMainTextboxRange()Returns theRangewhich covers all textboxes.OfficeDrawingsgetOfficeDrawingsHeaders()OfficeDrawingsgetOfficeDrawingsMain()RangegetOverallRange()Returns the range that covers all text in the file, including main text, footnotes, headers and commentsPicturesTablegetPicturesTable()RangegetRange()Returns the range which covers the whole of the document, but excludes any headers and footers.RevisionMarkAuthorTablegetRevisionMarkAuthorTable()Gets a reference to the revision mark author table, which holds the revision mark authors for the document.SavedByTablegetSavedByTable()Gets a reference to the saved -by table, which holds the save history for the document.byte[]getTableStream()java.lang.StringBuildergetText()Internal method to access document textTextPieceTablegetTextTable()intregisterList(HWPFList list)voidwrite()Write out the word file that is represented by this class, to the currently openFile, via the writeablePOIFSFileSystemit was opened as.voidwrite(java.io.File newFile)Writes out the word file that is represented by an instance of this class.voidwrite(java.io.OutputStream out)Writes out the word file that is represented by an instance of this class.-
Methods inherited from class org.apache.poi.hwpf.HWPFDocumentCore
getCharacterTable, getDocumentText, getEncryptionInfo, getFileInformationBlock, getFontTable, getListTables, getMainStream, getObjectsPool, getParagraphTable, getSectionTable, getStyleSheet, verifyAndBuildPOIFS
-
Methods inherited from class org.apache.poi.POIDocument
close, createInformationProperties, getDirectory, getDocumentSummaryInformation, getSummaryInformation
-
-
-
-
Constructor Detail
-
HWPFDocument
public HWPFDocument(java.io.InputStream istream) throws java.io.IOExceptionThis constructor loads a Word document from an InputStream.- Parameters:
istream- The InputStream that contains the Word document.- Throws:
java.io.IOException- If there is an unexpected IOException from the passed in InputStream.
-
HWPFDocument
public HWPFDocument(POIFSFileSystem pfilesystem) throws java.io.IOException
This constructor loads a Word document from a POIFSFileSystem- Parameters:
pfilesystem- The POIFSFileSystem that contains the Word document.- Throws:
java.io.IOException- If there is an unexpected IOException from the passed in POIFSFileSystem.
-
HWPFDocument
public HWPFDocument(DirectoryNode directory) throws java.io.IOException
This constructor loads a Word document from a specific point in a POIFSFileSystem, probably not the default. Used typically to open embeded documents.- Parameters:
directory- The DirectoryNode that contains the Word document.- Throws:
java.io.IOException- If there is an unexpected IOException from the passed in POIFSFileSystem.
-
-
Method Detail
-
getTextTable
@Internal public TextPieceTable getTextTable()
- Specified by:
getTextTablein classHWPFDocumentCore
-
getText
@Internal public java.lang.StringBuilder getText()
Description copied from class:HWPFDocumentCoreInternal method to access document text- Specified by:
getTextin classHWPFDocumentCore
-
getDocProperties
public DocumentProperties getDocProperties()
-
getOverallRange
public Range getOverallRange()
Description copied from class:HWPFDocumentCoreReturns the range that covers all text in the file, including main text, footnotes, headers and comments- Specified by:
getOverallRangein classHWPFDocumentCore
-
getRange
public Range getRange()
Returns the range which covers the whole of the document, but excludes any headers and footers.- Specified by:
getRangein classHWPFDocumentCore
-
getFootnoteRange
public Range getFootnoteRange()
Returns theRangewhich covers all the Footnotes.- Returns:
- the
Rangewhich covers all the Footnotes.
-
getEndnoteRange
public Range getEndnoteRange()
Returns theRangewhich covers all endnotes.- Returns:
- the
Rangewhich covers all endnotes.
-
getCommentsRange
public Range getCommentsRange()
Returns theRangewhich covers all annotations.- Returns:
- the
Rangewhich covers all annotations.
-
getMainTextboxRange
public Range getMainTextboxRange()
Returns theRangewhich covers all textboxes.- Returns:
- the
Rangewhich covers all textboxes.
-
getHeaderStoryRange
public Range getHeaderStoryRange()
Returns the range which covers all "Header Stories". A header story contains a header, footer, end note separators and footnote separators.
-
characterLength
public int characterLength()
Returns the character length of a document.- Returns:
- the character length of a document
-
getSavedByTable
@Internal public SavedByTable getSavedByTable()
Gets a reference to the saved -by table, which holds the save history for the document.- Returns:
- the saved-by table.
-
getRevisionMarkAuthorTable
@Internal public RevisionMarkAuthorTable getRevisionMarkAuthorTable()
Gets a reference to the revision mark author table, which holds the revision mark authors for the document.- Returns:
- the saved-by table.
-
getPicturesTable
public PicturesTable getPicturesTable()
- Returns:
- PicturesTable object, that is able to extract images from this document
-
getEscherRecordHolder
@Internal public EscherRecordHolder getEscherRecordHolder()
-
getOfficeDrawingsHeaders
public OfficeDrawings getOfficeDrawingsHeaders()
-
getOfficeDrawingsMain
public OfficeDrawings getOfficeDrawingsMain()
-
getBookmarks
public Bookmarks getBookmarks()
- Returns:
- user-friendly interface to access document bookmarks
-
getEndnotes
public Notes getEndnotes()
- Returns:
- user-friendly interface to access document endnotes
-
getFootnotes
public Notes getFootnotes()
- Returns:
- user-friendly interface to access document footnotes
-
getFieldsTables
@Deprecated @Internal public FieldsTables getFieldsTables()
Deprecated.POI 3.8.- Returns:
- FieldsTables object, that is able to extract fields descriptors from this document
-
getFields
public Fields getFields()
Returns user-friendly interface to access documentFields- Returns:
- user-friendly interface to access document
Fields
-
write
public void write() throws java.io.IOExceptionWrite out the word file that is represented by this class, to the currently openFile, via the writeablePOIFSFileSystemit was opened as.This will fail (with an
IllegalStateExceptionif the Document was opened read-only, opened from anInputStreaminstead of a File, or if this is not the root document. For those cases, you must usewrite(OutputStream)orwrite(File)to write to a brand new document.- Specified by:
writein classPOIDocument- Throws:
java.io.IOException- thrown on errors writing to the file- Since:
- 3.15
-
write
public void write(java.io.File newFile) throws java.io.IOExceptionWrites out the word file that is represented by an instance of this class. If theFileexists, it will be replaced, otherwise a new one will be created- Specified by:
writein classPOIDocument- Parameters:
newFile- The File to write to.- Throws:
java.io.IOException- If there is an unexpected IOException from writing to the File.- Since:
- 3.15 beta 3
-
write
public void write(java.io.OutputStream out) throws java.io.IOExceptionWrites out the word file that is represented by an instance of this class. For better performance when writing to files, usewrite(File). Ifstreamhas a high cost/latency associated with each written byte, consider wrapping the OutputStream in aBufferedOutputStreamto improve write performance.- Specified by:
writein classPOIDocument- Parameters:
out- The OutputStream to write to.- Throws:
java.io.IOException- If there is an unexpected IOException from the passed in OutputStream.
-
getDataStream
@Internal public byte[] getDataStream()
-
getTableStream
@Internal public byte[] getTableStream()
-
registerList
public int registerList(HWPFList list)
-
delete
public void delete(int start, int length)
-
-