/** * Inserts and empty paragraph into the end of this range. * * @param props * The properties that the new paragraph will have. * @param styleIndex * The index into the stylesheet for the new paragraph. * @return The newly inserted paragraph. * @deprecated POI 3.8 beta 4. Use code shall not work with {@link ParagraphProperties} */ @Deprecated Paragraph insertAfter(ParagraphProperties props, int styleIndex) { return this.insertAfter(props, styleIndex, "\r"); }
/** * Inserts and empty paragraph into the end of this range. * * @param props * The properties that the new paragraph will have. * @param styleIndex * The index into the stylesheet for the new paragraph. * @return The newly inserted paragraph. * @deprecated Use code shall not work with {@link ParagraphProperties} */ @Deprecated public Paragraph insertAfter(ParagraphProperties props, int styleIndex) // throws UnsupportedEncodingException { return this.insertAfter(props, styleIndex, "\r"); }
import java.io.*; import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.usermodel.*; public class test { public static void main(String[] args) throws Exception { // POI apparently can't create a document from scratch, // so we need an existing empty dummy document HWPFDocument doc = new HWPFDocument(new FileInputStream("D:\\src.doc")); Range range = doc.getRange(); CharacterRun run = range .insertAfter("Text After copied file contents!"); run.setBold(true); OutputStream out = new FileOutputStream("D:\\result.doc"); doc.write(out); out.flush(); out.close(); } }
/** * Inserts a list into the beginning of this range. * * @param props * The properties of the list entry. All list entries are * paragraphs. * @param listID * The id of the list that contains the properties. * @param level * The indentation level of the list. * @param styleIndex * The base style's index in the stylesheet. * @return The empty ListEntry that is now part of the document. * @deprecated Use code shall not work with {@link ParagraphProperties} */ @Deprecated public ListEntry insertAfter(ParagraphProperties props, int listID, int level, int styleIndex) { ListTables lt = _doc.getListTables(); if (lt.getLevel(listID, level) == null) { throw new NoSuchElementException("The specified list and level do not exist"); } int ilfo = lt.getOverrideIndexFromListID(listID); props.setIlfo(ilfo); props.setIlvl((byte) level); return (ListEntry) insertAfter(props, styleIndex); }
/** * Inserts text onto the end of this range and gives that text the * CharacterProperties specified in props. * * @param text * The text to insert. * @param props * The CharacterProperties to give the text. * @return A new CharacterRun that has the given text and properties and is * n ow a part of the document. * @deprecated POI 3.8 beta 4. User code should not work with {@link CharacterProperties} */ @Deprecated private CharacterRun insertAfter(String text, CharacterProperties props) { initAll(); PAPX papx = _paragraphs.get(_parEnd - 1); short istd = papx.getIstd(); StyleSheet ss = _doc.getStyleSheet(); CharacterProperties baseStyle = ss.getCharacterStyle(istd); byte[] grpprl = CharacterSprmCompressor.compressCharacterProperty(props, baseStyle); SprmBuffer buf = new SprmBuffer(grpprl, 0); _doc.getCharacterTable().insert(_charEnd, _end, buf); _charEnd++; return insertAfter(text); }
/** * Inserts text onto the end of this range and gives that text the * CharacterProperties specified in props. * * @param text * The text to insert. * @param props * The CharacterProperties to give the text. * @return A new CharacterRun that has the given text and properties and is * n ow a part of the document. * @deprecated User code should not work with {@link CharacterProperties} */ @Deprecated public CharacterRun insertAfter(String text, CharacterProperties props) // throws UnsupportedEncodingException { initAll(); PAPX papx = _paragraphs.get(_parEnd - 1); short istd = papx.getIstd(); StyleSheet ss = _doc.getStyleSheet(); CharacterProperties baseStyle = ss.getCharacterStyle(istd); byte[] grpprl = CharacterSprmCompressor.compressCharacterProperty(props, baseStyle); SprmBuffer buf = new SprmBuffer(grpprl, 0); _doc.getCharacterTable().insert(_charEnd, _end, buf); _charEnd++; return insertAfter(text); }
/** * Replace range text with new one, adding it to the range and deleting * original text from document * * @param newText * The text to be replaced with * @param addAfter * if <tt>true</tt> the text will be added at the end of current * range, otherwise to the beginning */ public void replaceText( String newText, boolean addAfter ) { if ( addAfter ) { int originalEnd = getEndOffset(); insertAfter( newText ); new Range( getStartOffset(), originalEnd, this ).delete(); } else { int originalStart = getStartOffset(); int originalEnd = getEndOffset(); insertBefore( newText ); new Range( originalStart + newText.length(), originalEnd + newText.length(), this ).delete(); } }
/** * Replace range text with new one, adding it to the range and deleting * original text from document * * @param newText * The text to be replaced with * @param addAfter * if <tt>true</tt> the text will be added at the end of current * range, otherwise to the beginning */ public void replaceText( String newText, boolean addAfter ) { if ( addAfter ) { int originalEnd = getEndOffset(); insertAfter( newText ); new Range( getStartOffset(), originalEnd, this ).delete(); } else { int originalStart = getStartOffset(); int originalEnd = getEndOffset(); insertBefore( newText ); new Range( originalStart + newText.length(), originalEnd + newText.length(), this ).delete(); } }
insertAfter(text, baseChp); return getParagraph(numParagraphs() - 1);
insertAfter(text, baseChp); return getParagraph(numParagraphs() - 1);
fis.close(); Range range = doc.getRange(); CharacterRun run1 = range.insertAfter("Sample text"); run1.setFontSize(11); return doc;