本文整理汇总了Java中org.apache.poi.xwpf.usermodel.XWPFDocument.createParagraph方法的典型用法代码示例。如果您正苦于以下问题:Java XWPFDocument.createParagraph方法的具体用法?Java XWPFDocument.createParagraph怎么用?Java XWPFDocument.createParagraph使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.xwpf.usermodel.XWPFDocument
的用法示例。
在下文中一共展示了XWPFDocument.createParagraph方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDOCXDocument
import org.apache.poi.xwpf.usermodel.XWPFDocument; //导入方法依赖的package包/类
void createDOCXDocument(String pdfText, String outputFileName){
XWPFDocument pdfTextDocument = new XWPFDocument();
XWPFParagraph pdfTextParagraph = pdfTextDocument.createParagraph();;
XWPFRun pdfTextParagraphCharacterRun = pdfTextParagraph.createRun();
StringTokenizer pdfTextReader = new StringTokenizer(pdfText);
String pdfTextLine = null;
while(pdfTextReader.hasMoreTokens()){
pdfTextLine = pdfTextReader.nextToken("\n");
pdfTextParagraphCharacterRun.setText(pdfTextLine);
pdfTextParagraphCharacterRun.addCarriageReturn();
}
try{
pdfTextDocument.write(new FileOutputStream(new File(outputFileName)));
}
catch(Exception e){
System.err.println("An exception occured in creating the DOCX document."+ e.getMessage());
}
}
示例2: main
import org.apache.poi.xwpf.usermodel.XWPFDocument; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
// Create a new document from scratch
XWPFDocument doc = new XWPFDocument();
// create paragraph
XWPFParagraph para = doc.createParagraph();
// create a run to contain the content
XWPFRun rh = para.createRun();
// Format as desired
rh.setFontSize(15);
rh.setFontFamily("Verdana");
rh.setText("This is the formatted Text");
rh.setColor("fff000");
para.setAlignment(ParagraphAlignment.RIGHT);
// write the file
FileOutputStream out = new FileOutputStream("data/Apache_FormattedText.docx");
doc.write(out);
out.close();
System.out.println("Process Completed Successfully");
}
示例3: main
import org.apache.poi.xwpf.usermodel.XWPFDocument; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
XWPFDocument doc = new XWPFDocument();
XWPFParagraph p = doc.createParagraph();
String imgFile = "aspose.jpg";
XWPFRun r = p.createRun();
int format = XWPFDocument.PICTURE_TYPE_JPEG;
r.setText(imgFile);
r.addBreak();
r.addPicture(new FileInputStream(imgFile), format, imgFile, Units.toEMU(200), Units.toEMU(200)); // 200x200 pixels
r.addBreak(BreakType.PAGE);
FileOutputStream out = new FileOutputStream("data/Apache_ImagesInDoc.docx");
doc.write(out);
out.close();
System.out.println("Process Completed Successfully");
}
示例4: main
import org.apache.poi.xwpf.usermodel.XWPFDocument; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
String dataPath = "src/featurescomparison/workingwithdocuments/savedocument/data/";
XWPFDocument document = new XWPFDocument();
XWPFParagraph tmpParagraph = document.createParagraph();
XWPFRun tmpRun = tmpParagraph.createRun();
tmpRun.setText("Apache Sample Content for Word file.");
FileOutputStream fos = new FileOutputStream(dataPath + "Apache_SaveDoc_Out.doc");
document.write(fos);
fos.close();
System.out.println("Process Completed Successfully");
}
示例5: main
import org.apache.poi.xwpf.usermodel.XWPFDocument; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
String dataPath = "src/featurescomparison/workingwithdocuments/formattext/data/";
// Create a new document from scratch
XWPFDocument doc = new XWPFDocument();
// create paragraph
XWPFParagraph para = doc.createParagraph();
// create a run to contain the content
XWPFRun rh = para.createRun();
// Format as desired
rh.setFontSize(15);
rh.setFontFamily("Verdana");
rh.setText("This is the formatted Text");
rh.setColor("fff000");
para.setAlignment(ParagraphAlignment.RIGHT);
// write the file
FileOutputStream out = new FileOutputStream(dataPath + "Apache_FormattedText_Out.docx");
doc.write(out);
out.close();
System.out.println("Process Completed Successfully");
}
示例6: main
import org.apache.poi.xwpf.usermodel.XWPFDocument; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
String dataPath = "src/featurescomparison/workingwithimages/insertimage/data/";
XWPFDocument doc = new XWPFDocument();
XWPFParagraph p = doc.createParagraph();
String imgFile = dataPath + "aspose.jpg";
XWPFRun r = p.createRun();
int format = XWPFDocument.PICTURE_TYPE_JPEG;
r.setText(imgFile);
r.addBreak();
r.addPicture(new FileInputStream(imgFile), format, imgFile, Units.toEMU(200), Units.toEMU(200)); // 200x200 pixels
r.addBreak(BreakType.PAGE);
FileOutputStream out = new FileOutputStream(dataPath + "Apache_ImagesInDoc_Out.docx");
doc.write(out);
out.close();
System.out.println("Process Completed Successfully");
}
示例7: writeParagraph
import org.apache.poi.xwpf.usermodel.XWPFDocument; //导入方法依赖的package包/类
/**
* Método que se encarga de escribir un texto en un párrafo
* de un documento Microsoft Word
* @param document El documento word que se va a crear
* @param text El texto a meter en el word
*/
private void writeParagraph(XWPFDocument document,String text){
XWPFParagraph paragraph = document.createParagraph();
paragraph.setAlignment(ParagraphAlignment.BOTH);
paragraph.createRun().setText(text);
paragraph.createRun().setFontSize(12);
paragraph.createRun().addCarriageReturn();
}
示例8: createDocumentTemplate
import org.apache.poi.xwpf.usermodel.XWPFDocument; //导入方法依赖的package包/类
/**
* Creates a new {@link DocumentTemplate} with the given {@link DocumentTemplate#getBody() body}. The body is linked to {@link XWPFRun}.
*
* @param body
* the {@link Template}
* @return a new {@link DocumentTemplate}
*/
@SuppressWarnings("resource")
public static DocumentTemplate createDocumentTemplate(Template body) {
final DocumentTemplate res = TemplatePackage.eINSTANCE.getTemplateFactory().createDocumentTemplate();
final XWPFDocument document = new XWPFDocument();
res.setDocument(document);
res.setBody(body);
final XWPFParagraph paragraph = document.createParagraph();
linkRuns(paragraph, body);
return res;
}
示例9: main
import org.apache.poi.xwpf.usermodel.XWPFDocument; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
XWPFDocument document = new XWPFDocument();
XWPFParagraph tmpParagraph = document.createParagraph();
XWPFRun tmpRun = tmpParagraph.createRun();
tmpRun.setText("Apache Sample Content for Word file.");
tmpRun.setFontSize(18);
FileOutputStream fos = new FileOutputStream("data/Apache_newWordDoc.doc");
document.write(fos);
fos.close();
}
示例10: main
import org.apache.poi.xwpf.usermodel.XWPFDocument; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
XWPFDocument document = new XWPFDocument();
XWPFParagraph tmpParagraph = document.createParagraph();
XWPFRun tmpRun = tmpParagraph.createRun();
tmpRun.setText("Apache Sample Content for Word file.");
FileOutputStream fos = new FileOutputStream("data/Apache_SaveDoc.doc");
document.write(fos);
fos.close();
System.out.println("Process Completed Successfully");
}
示例11: main
import org.apache.poi.xwpf.usermodel.XWPFDocument; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
String dataPath = "src/featurescomparison/workingwithdocuments/createnewdocument/data/";
XWPFDocument document = new XWPFDocument();
XWPFParagraph tmpParagraph = document.createParagraph();
XWPFRun tmpRun = tmpParagraph.createRun();
tmpRun.setText("Apache Sample Content for Word file.");
tmpRun.setFontSize(18);
FileOutputStream fos = new FileOutputStream(dataPath + "Apache_newWordDoc_Out.doc");
document.write(fos);
fos.close();
}
示例12: saveStylesToDocxFile
import org.apache.poi.xwpf.usermodel.XWPFDocument; //导入方法依赖的package包/类
/**
* ����text��������ʽ��docx��ʽ�ļ�
*/
@SuppressWarnings("deprecation")
public void saveStylesToDocxFile(StyledText text, XWPFDocument document) {
for (int i = 0; i < text.getLineCount(); ++i) {
int lineOffset = text.getOffsetAtLine(i);
String lineText = text.getLine(i);
XWPFParagraph paragraph = document.createParagraph();
paragraph.setFirstLineIndent(text.getIndent());
int lineAlignment = text.getLineAlignment(i);
switch (lineAlignment) {
case SWT.RIGHT:
paragraph.setAlignment(ParagraphAlignment.RIGHT);
break;
case SWT.CENTER:
paragraph.setAlignment(ParagraphAlignment.CENTER);
break;
}
// ����ÿһ�����ÿ���ַ�
for (int a = lineOffset; a < lineOffset + lineText.length(); ++a) {
StyleRange charStyle = text.getStyleRangeAtOffset(a);
String charText = text.getText(a, a);
XWPFRun run = paragraph.createRun();
run.setText(charText);
String fontname = null;
int fontsize = 0;
if (charStyle != null) {
// Color background = charStyle.background;
// Color foreground = charStyle.foreground;
if (charStyle.font != null) {
fontname = charStyle.font.getFontData()[0].getName();
if (b.text != null && text.equals(b.text))
fontsize = b.getFontRealSize(charStyle.font.getFontData()[0].getHeight());
else
fontsize = text.getFont().getFontData()[0].getHeight();
}
int fontstyle = charStyle.fontStyle;
switch (fontstyle) {
case SWT.BOLD:
run.setBold(true);
break;
case SWT.ITALIC:
run.setItalic(true);
break;
case SWT.BOLD | SWT.ITALIC:
run.setBold(true);
run.setItalic(true);
break;
}
run.setStrike(charStyle.strikeout);
if (charStyle.underline)
run.setUnderline(UnderlinePatterns.SINGLE);
run.setFontFamily(fontname, FontCharRange.eastAsia);
run.setFontSize(fontsize);
}
}
}
}
示例13: processSingleItem
import org.apache.poi.xwpf.usermodel.XWPFDocument; //导入方法依赖的package包/类
void processSingleItem(XWPFDocument document, String citationText, String abstractText, String handleUrl) {
XWPFParagraph para = document.createParagraph();
XWPFRun run = para.createRun();
run.setText(StringUtils.isNotBlank(citationText) ? citationText : "(no citation)");
para.setSpacingAfter(200);
if (StringUtils.isNotBlank(handleUrl)) {
// from http://stackoverflow.com/a/22456273/72625
String linkId = document.getPackagePart().addExternalRelationship(handleUrl, XWPFRelation.HYPERLINK.getRelation()).getId();
para = document.createParagraph();
para.setSpacingAfter(200);
XWPFRun linkPrefix = para.createRun();
CTText linkPrefixText = linkPrefix.getCTR().addNewT();
linkPrefixText.setStringValue("AgScite record: ");
linkPrefixText.setSpace(SpaceAttribute.Space.PRESERVE);
CTHyperlink link = para.getCTP().addNewHyperlink();
link.setId(linkId);
CTText linkText = CTText.Factory.newInstance();
linkText.setStringValue(handleUrl);
CTR ctr = CTR.Factory.newInstance();
ctr.setTArray(new CTText[]{linkText});
ctr.addNewRPr().addNewColor().setVal("0000FF");
ctr.addNewRPr().addNewU().setVal(STUnderline.SINGLE);
link.setRArray(new CTR[]{ctr});
}
if (includeAbstract && StringUtils.isNotBlank(abstractText)) {
// split md string at double newline so we can create actual paragraphs
String[] abstractParas = abstractText.split("\r?\n\r?\n");
for (String abstractPara : abstractParas) {
para = document.createParagraph();
run = para.createRun();
run.setText(abstractPara);
para.setSpacingAfter(200);
para.setIndentationLeft(200);
}
}
para.setSpacingAfter(600); // override spacing for final para
}
示例14: createDocument
import org.apache.poi.xwpf.usermodel.XWPFDocument; //导入方法依赖的package包/类
@Override
public void createDocument(String documentName, String content) throws CitizenException {
XWPFDocument doc = new XWPFDocument();
XWPFParagraph pg = doc.createParagraph();
XWPFRun run = pg.createRun();
run.setFontFamily("Calibri");
run.setFontSize(20);
run.setText(content);
try {
FileOutputStream out = new FileOutputStream(FILE_PATH+documentName+".docx");
doc.write(out);
out.close();
doc.close();
} catch (IOException e) {
throw new CitizenException("Error al generar documento word" +
" ["+ FILE_PATH+documentName+".docx] | ["+this.getClass().getName()+"]");
}
}