本文整理汇总了Java中org.apache.poi.xwpf.usermodel.XWPFParagraph.setAlignment方法的典型用法代码示例。如果您正苦于以下问题:Java XWPFParagraph.setAlignment方法的具体用法?Java XWPFParagraph.setAlignment怎么用?Java XWPFParagraph.setAlignment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.xwpf.usermodel.XWPFParagraph
的用法示例。
在下文中一共展示了XWPFParagraph.setAlignment方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入方法依赖的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");
}
示例2: addText
import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入方法依赖的package包/类
/**
* 텍스트 입력
*
* @param p
* @param text
* @param fontSize
* @param bold
* @param italic
* @param strike
* @return
*/
public XWPFParagraph addText(XWPFParagraph p, String text, int fontSize, boolean bold, boolean italic, boolean strike) {
KrXWPFRun r1 = new KrXWPFRun(p.createRun());
r1.setText(text);
r1.setBold(bold);
r1.setItalic(italic);
r1.setFontFamily(fontName);
// r1.setUnderline(UnderlinePatterns.DOT_DOT_DASH);
r1.setStrike(strike);
r1.setFontSize(fontSize);
p.setAlignment(ParagraphAlignment.LEFT);
// p.setSpacingLineRule(LineSpacingRule.EXACT);
return p;
}
示例3: addBlockText
import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入方法依赖的package包/类
/**
* 텍스트 입력
*
* @param text
*/
public void addBlockText(String text, ParagraphAlignment alignment) {
XWPFParagraph p1 = doc.createParagraph();
p1.setAlignment(alignment);
p1.setBorderBottom(Borders.DOUBLE);
p1.setBorderTop(Borders.DOUBLE);
p1.setBorderRight(Borders.DOUBLE);
p1.setBorderLeft(Borders.DOUBLE);
p1.setBorderBetween(Borders.SINGLE);
p1.setVerticalAlignment(TextAlignment.TOP);
// p1.setSpacingBefore(5);
// p1.setSpacingAfter(5);
// KrXWPFRun r1 = new KrXWPFRun(p1.createRun());
// r1.setFontSize(13);
// r1.setText(text);
// r1.setFontFamily(fontName);
addText(p1, text);
}
示例4: createCellText
import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入方法依赖的package包/类
public void createCellText(XWPFTableCell cell) {
XWPFParagraph paragraph;
// If no header is set, use the cell's default paragraph.
if (cell.getParagraphs().get(0).getRuns().size() == 0)
paragraph = cell.getParagraphs().get(0);
else
paragraph = cell.addParagraph();
XWPFRun run = paragraph.createRun();
run.setBold(isBold);
run.setText(text);
run.setFontFamily(fontFamily);
run.setFontSize(fontSize);
paragraph.setAlignment(alignment);
paragraph.setSpacingAfter(10);
paragraph.setSpacingBefore(topMargin);
paragraph.setIndentationLeft(leftMargin);
paragraph.setIndentationRight(50);
paragraph.setIndentationHanging(hangingIndent);
if (bottomBorder)
paragraph.setBorderBottom(Borders.SINGLE);
}
示例5: createCellHeader
import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入方法依赖的package包/类
public void createCellHeader(XWPFTableCell cell) {
XWPFParagraph p;
if (cell.getParagraphs().get(0).getRuns().size() == 0)
p = cell.getParagraphs().get(0);
else
p = cell.addParagraph();
p.setAlignment(alignment);
p.setSpacingBefore(beforeSpacing);
p.setIndentationLeft(20);
p.setSpacingAfter(100);
XWPFRun rHeading = p.createRun();
rHeading.setText(text.toUpperCase());
rHeading.setFontFamily("Arial");
rHeading.setFontSize(6);
rHeading.setBold(isBold);
}
示例6: main
import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入方法依赖的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");
}
示例7: writeParagraph
import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入方法依赖的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: saveStylesToDocxFile
import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入方法依赖的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);
}
}
}
}