Я новичок в API POI и, следовательно, всякий раз, когда я использую класс HWPFDocument для записи текста в файл .doc, созданный Документом HWPF, полученный файл документа содержит только одну букву, а не весь текст,Я написал.
Поэтому, пожалуйста, дайте ответ, как я могу добавить к нему больше текста.
Это код:
/**
* Create a POIFSFileSystem from an InputStream.
* Test.doc is an empty doc with no contents
*/
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("test.doc"));
/**
* Horrible word Document Format
*/
HWPFDocument hwpfDocument = new HWPFDocument(fs);
/**
* range is used for getting the range of the document except header and footer
*/
Range range = hwpfDocument.getRange();
range.numParagraphs();
/**
* creating Paragraph
*/
/**
* Inserts a paragraph into the end of this range.
* ParagraphProperties -> for creating Paragraph, index of the paragraph
*/
/*Paragraph paragraph1 = range.insertBefore(new ParagraphProperties(), 0);
paragraph1.setJustification((byte) 0); // 0-left, 1-center, 2-right, 3-left and right*/
CharacterRun characterRun1 = range.insertBefore("Document");
/**
* setting the font size
*/
characterRun1.setFontSize(2 * 12); // takes as an argument half points
/**
* making Text Bold Italic
*/
characterRun1.setBold(true);
characterRun1.setItalic(true);
characterRun1.setColor(111);
characterRun1.setData(true);
//characterRun1.replaceWith("Document");
hwpfDocument.write(new FileOutputStream("hpwf-create-doc.doc", true));