本文整理汇总了Java中org.docx4j.wml.PPr.setPStyle方法的典型用法代码示例。如果您正苦于以下问题:Java PPr.setPStyle方法的具体用法?Java PPr.setPStyle怎么用?Java PPr.setPStyle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.docx4j.wml.PPr
的用法示例。
在下文中一共展示了PPr.setPStyle方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTblStyle_BasedOnNormal
import org.docx4j.wml.PPr; //导入方法依赖的package包/类
@Test
public void testTblStyle_BasedOnNormal() throws Exception {
// Compat setting says Paragraph style overrides table style
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
wordMLPackage.getMainDocumentPart().setContents(
(Document)XmlUtils.unmarshalString(mdpXml_tblStyle) );
wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents(
(Styles)XmlUtils.unmarshalString(styles_in_basedOn_Normal) );
// Use our style!
List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", true);
PPr ppr = Context.getWmlObjectFactory().createPPr();
((P)xpathResults.get(0)).setPPr(ppr);
PStyle ps = Context.getWmlObjectFactory().createPPrBasePStyle();
ps.setVal("testStyle");
ppr.setPStyle(ps);
setSetting(wordMLPackage, OVERRIDE); // table style should get overridden
wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
ParagraphStylesInTableFix.process(wordMLPackage);
// // Revert style and save:
// ppr.setPStyle(ps); // doesn't work - wrong ref!
// wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
Style ours = null;
for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) {
if ("testStyle-TableGrid-BR".equals(s.getStyleId())) {
ours = s;
break;
}
}
// Style s = getStyle(wordMLPackage, STYLE_NAME);
Assert.assertTrue(ours.getRPr().getSz().getVal().intValue()==24);
}
示例2: testTblStyle_BasedOnNormal
import org.docx4j.wml.PPr; //导入方法依赖的package包/类
@Test
public void testTblStyle_BasedOnNormal() throws Exception {
// A style basedOn Normal is honoured, provided it (not Normal) contributes the font size
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
wordMLPackage.getMainDocumentPart().setContents(
(Document)XmlUtils.unmarshalString(mdpXml_tblStyle) );
wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents(
(Styles)XmlUtils.unmarshalString(styles_in_basedOn_Normal) );
// Use our style!
List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", true);
PPr ppr = Context.getWmlObjectFactory().createPPr();
((P)xpathResults.get(0)).setPPr(ppr);
PStyle ps = Context.getWmlObjectFactory().createPPrBasePStyle();
ps.setVal("testStyle");
ppr.setPStyle(ps);
setSetting(wordMLPackage, OVERRIDE);
wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
ParagraphStylesInTableFix.process(wordMLPackage);
// // Revert style and save:
// ppr.setPStyle(ps); // doesn't work - wrong ref!
// wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
Style ours = null;
for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) {
if ("testStyle-TableNormal-BR".equals(s.getStyleId())) {
ours = s;
break;
}
}
// Style s = getStyle(wordMLPackage, STYLE_NAME);
Assert.assertTrue(ours.getRPr().getSz().getVal().intValue()==EXPECTED_RESULT);
}
示例3: testTblStyle_BasedOn_Normal12
import org.docx4j.wml.PPr; //导入方法依赖的package包/类
@Test
public void testTblStyle_BasedOn_Normal12() throws Exception {
// Compat setting says Paragraph style overrides table style
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
wordMLPackage.getMainDocumentPart().setContents(
(Document)XmlUtils.unmarshalString(mdpXml_tblStyle) );
wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents(
(Styles)XmlUtils.unmarshalString(styles_basedOn_Normal) );
// Use our style!
List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", true);
PPr ppr = Context.getWmlObjectFactory().createPPr();
((P)xpathResults.get(0)).setPPr(ppr);
PStyle ps = Context.getWmlObjectFactory().createPPrBasePStyle();
ps.setVal("testStyle");
ppr.setPStyle(ps);
setSetting(wordMLPackage, OVERRIDE);
wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
ParagraphStylesInTableFix.process(wordMLPackage);
// // Revert style and save:
// ppr.setPStyle(ps); // doesn't work - wrong ref!
// wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
Style ours = null;
for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) {
if ("testStyle-TableGrid-BR".equals(s.getStyleId())) {
ours = s;
break;
}
}
// Style s = getStyle(wordMLPackage, STYLE_NAME);
Assert.assertTrue(ours.getRPr().getSz().getVal().intValue()==EXPECTED_RESULT);
}
示例4: testTblStyle_BasedOnNormal
import org.docx4j.wml.PPr; //导入方法依赖的package包/类
@Test
public void testTblStyle_BasedOnNormal() throws Exception {
// A style basedOn Normal is honoured, provided it (not Normal) contributes the font size
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
wordMLPackage.getMainDocumentPart().setContents(
(Document)XmlUtils.unmarshalString(mdpXml_tblStyle) );
wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents(
(Styles)XmlUtils.unmarshalString(styles_in_basedOn_Normal) );
// Use our style!
List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", true);
PPr ppr = Context.getWmlObjectFactory().createPPr();
((P)xpathResults.get(0)).setPPr(ppr);
PStyle ps = Context.getWmlObjectFactory().createPPrBasePStyle();
ps.setVal("testStyle");
ppr.setPStyle(ps);
setSetting(wordMLPackage, OVERRIDE);
wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
ParagraphStylesInTableFix.process(wordMLPackage);
// // Revert style and save:
// ppr.setPStyle(ps); // doesn't work - wrong ref!
// wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
Style ours = null;
for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) {
if ("testStyle-TableGrid-BR".equals(s.getStyleId())) {
ours = s;
break;
}
}
// Style s = getStyle(wordMLPackage, STYLE_NAME);
Assert.assertTrue(ours.getRPr().getSz().getVal().intValue()==24);
}
示例5: testTblStyle_BasedOn_Normal12
import org.docx4j.wml.PPr; //导入方法依赖的package包/类
@Test
public void testTblStyle_BasedOn_Normal12() throws Exception {
// A style basedOn Normal is ignored where the font size comes from Normal
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
wordMLPackage.getMainDocumentPart().setContents(
(Document)XmlUtils.unmarshalString(mdpXml_tblStyle) );
wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents(
(Styles)XmlUtils.unmarshalString(styles_basedOn_Normal) );
// Use our style!
List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", true);
PPr ppr = Context.getWmlObjectFactory().createPPr();
((P)xpathResults.get(0)).setPPr(ppr);
PStyle ps = Context.getWmlObjectFactory().createPPrBasePStyle();
ps.setVal("testStyle");
ppr.setPStyle(ps);
setSetting(wordMLPackage, OVERRIDE);
wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
ParagraphStylesInTableFix.process(wordMLPackage);
// // Revert style and save:
// ppr.setPStyle(ps); // doesn't work - wrong ref!
// wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
Style ours = null;
for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) {
if ("testStyle-TableGrid-BR".equals(s.getStyleId())) {
ours = s;
break;
}
}
// Style s = getStyle(wordMLPackage, STYLE_NAME);
Assert.assertTrue(ours.getRPr().getSz().getVal().intValue()==EXPECTED_RESULT);
}
示例6: testTblStyle_BasedOnNormal
import org.docx4j.wml.PPr; //导入方法依赖的package包/类
@Test
public void testTblStyle_BasedOnNormal() throws Exception {
// Compat setting says Paragraph style overrides table style
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
wordMLPackage.getMainDocumentPart().setContents(
(Document)XmlUtils.unmarshalString(mdpXml_tblStyle) );
wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents(
(Styles)XmlUtils.unmarshalString(styles_in_basedOn_Normal) );
// Use our style!
List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", true);
PPr ppr = Context.getWmlObjectFactory().createPPr();
((P)xpathResults.get(0)).setPPr(ppr);
PStyle ps = Context.getWmlObjectFactory().createPPrBasePStyle();
ps.setVal("testStyle");
ppr.setPStyle(ps);
setSetting(wordMLPackage, OVERRIDE); // table style should get overridden
wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
ParagraphStylesInTableFix.process(wordMLPackage);
// // Revert style and save:
// ppr.setPStyle(ps); // doesn't work - wrong ref!
// wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
Style ours = null;
for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) {
if ("testStyle-TableGrid-BR".equals(s.getStyleId())) {
ours = s;
break;
}
}
// Style s = getStyle(wordMLPackage, STYLE_NAME);
Assert.assertTrue(ours.getRPr().getSz().getVal().intValue()==EXPECTED_RESULT);
}
示例7: testTblStyle_BasedOnNormal
import org.docx4j.wml.PPr; //导入方法依赖的package包/类
@Test
@Ignore
public void testTblStyle_BasedOnNormal() throws Exception {
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
wordMLPackage.getMainDocumentPart().setContents(
(Document)XmlUtils.unmarshalString(mdpXml_tblStyle) );
wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents(
(Styles)XmlUtils.unmarshalString(styles_in_basedOn_Normal) );
// Use our style!
List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", true);
PPr ppr = Context.getWmlObjectFactory().createPPr();
((P)xpathResults.get(0)).setPPr(ppr);
PStyle ps = Context.getWmlObjectFactory().createPPrBasePStyle();
ps.setVal("testStyle");
ppr.setPStyle(ps);
setSetting(wordMLPackage, OVERRIDE);
wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
ParagraphStylesInTableFix.process(wordMLPackage);
// // Revert style and save:
// ppr.setPStyle(ps); // doesn't work - wrong ref!
// wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
Style ours = null;
for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) {
if ("testStyle-TableGrid-BR".equals(s.getStyleId())) {
ours = s;
break;
}
}
// Style s = getStyle(wordMLPackage, STYLE_NAME);
Assert.assertTrue(ours.getRPr().getSz().getVal().intValue()==22);
}
示例8: testTblStyle_BasedOn_Normal11
import org.docx4j.wml.PPr; //导入方法依赖的package包/类
@Test
@Ignore
public void testTblStyle_BasedOn_Normal11() throws Exception {
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
wordMLPackage.getMainDocumentPart().setContents(
(Document)XmlUtils.unmarshalString(mdpXml_tblStyle) );
wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents(
(Styles)XmlUtils.unmarshalString(styles_basedOn_Normal) );
// Use our style!
List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", true);
PPr ppr = Context.getWmlObjectFactory().createPPr();
((P)xpathResults.get(0)).setPPr(ppr);
PStyle ps = Context.getWmlObjectFactory().createPPrBasePStyle();
ps.setVal("testStyle");
ppr.setPStyle(ps);
setSetting(wordMLPackage, OVERRIDE);
wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
ParagraphStylesInTableFix.process(wordMLPackage);
// // Revert style and save:
// ppr.setPStyle(ps); // doesn't work - wrong ref!
// wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
Style ours = null;
for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) {
if ("testStyle-TableGrid-BR".equals(s.getStyleId())) {
ours = s;
break;
}
}
// Style s = getStyle(wordMLPackage, STYLE_NAME);
Assert.assertTrue(ours.getRPr().getSz().getVal().intValue()==22);
}
示例9: testTblStyle_BasedOnNormal
import org.docx4j.wml.PPr; //导入方法依赖的package包/类
@Test
public void testTblStyle_BasedOnNormal() throws Exception {
// Compat setting says Paragraph style overrides table style
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
wordMLPackage.getMainDocumentPart().setContents(
(Document)XmlUtils.unmarshalString(mdpXml_tblStyle) );
wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents(
(Styles)XmlUtils.unmarshalString(styles_in_basedOn_Normal) );
// Use our style!
List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", true);
PPr ppr = Context.getWmlObjectFactory().createPPr();
((P)xpathResults.get(0)).setPPr(ppr);
PStyle ps = Context.getWmlObjectFactory().createPPrBasePStyle();
ps.setVal("testStyle");
ppr.setPStyle(ps);
setSetting(wordMLPackage, OVERRIDE); // table style should get overridden
wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
ParagraphStylesInTableFix.process(wordMLPackage);
// // Revert style and save:
// ppr.setPStyle(ps); // doesn't work - wrong ref!
// wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
Style ours = null;
for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) {
if ("testStyle-TableNormal-BR".equals(s.getStyleId())) {
ours = s;
break;
}
}
// Style s = getStyle(wordMLPackage, STYLE_NAME);
Assert.assertTrue(ours.getRPr().getSz().getVal().intValue()==EXPECTED_RESULT);
}
示例10: createParagraph
import org.docx4j.wml.PPr; //导入方法依赖的package包/类
private P createParagraph(final String styleId, final R... runs) {
final P p = this.wmlObjectFactory.createP();
final PPr ppr = this.wmlObjectFactory.createPPr();
p.setPPr(ppr);
final PStyle pstyle = this.wmlObjectFactory.createPPrBasePStyle();
pstyle.setVal(styleId);
ppr.setPStyle(pstyle);
p.getContent().addAll(Arrays.asList(runs));
return p;
}
示例11: apply
import org.docx4j.wml.PPr; //导入方法依赖的package包/类
@Override
public void apply(P p, Object parent, List<Object> siblings) {
//apply the inline style for each run
SingleTraversalUtilVisitorCallback runVisitor = new SingleTraversalUtilVisitorCallback(new TraversalUtilRunVisitor());
runVisitor.walkJAXBElements(p);
ObjectFactory wmlObjectFactory = new ObjectFactory();
PPr ppr = p.getPPr();
if (ppr==null) {
ppr = wmlObjectFactory.createPPr();
p.setPPr(ppr);
}
//apply the inline style for run at paragraph level
if (runWithTextFound) {
if (inlineContentStyleIsParagraphStyle) {
// Create object for pStyle
PPrBase.PStyle pprbasepstyle = wmlObjectFactory.createPPrBasePStyle();
ppr.setPStyle(pprbasepstyle);
pprbasepstyle.setVal(inlineStyleId);
} else {
// Create object for rStyle
RStyle rstyle = wmlObjectFactory.createRStyle();
ParaRPr paraRpr = ppr.getRPr();
if (paraRpr==null) {
paraRpr = wmlObjectFactory.createParaRPr();
ppr.setRPr(paraRpr);
}
paraRpr.setRStyle(rstyle);
rstyle.setVal(inlineStyleId);
}
}
runWithTextFound = false;
}
示例12: testTblStyle_BasedOn_Normal12
import org.docx4j.wml.PPr; //导入方法依赖的package包/类
@Test
public void testTblStyle_BasedOn_Normal12() throws Exception {
// A style basedOn Normal is ignored where the font size comes from Normal
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
wordMLPackage.getMainDocumentPart().setContents(
(Document)XmlUtils.unmarshalString(mdpXml_tblStyle) );
wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents(
(Styles)XmlUtils.unmarshalString(styles_basedOn_Normal) );
// Use our style!
List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", true);
PPr ppr = Context.getWmlObjectFactory().createPPr();
((P)xpathResults.get(0)).setPPr(ppr);
PStyle ps = Context.getWmlObjectFactory().createPPrBasePStyle();
ps.setVal("testStyle");
ppr.setPStyle(ps);
setSetting(wordMLPackage, OVERRIDE);
wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
ParagraphStylesInTableFix.process(wordMLPackage);
// // Revert style and save:
// ppr.setPStyle(ps); // doesn't work - wrong ref!
// wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
Style ours = null;
for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) {
if ("testStyle-TableNormal-BR".equals(s.getStyleId())) {
ours = s;
break;
}
}
// Style s = getStyle(wordMLPackage, STYLE_NAME);
assertSz(ours, EXPECTED_RESULT);
}
示例13: testTblStyle_BasedOn_Normal12
import org.docx4j.wml.PPr; //导入方法依赖的package包/类
@Test
public void testTblStyle_BasedOn_Normal12() throws Exception {
// Compat setting says Paragraph style overrides table style
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
wordMLPackage.getMainDocumentPart().setContents(
(Document)XmlUtils.unmarshalString(mdpXml_tblStyle) );
wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents(
(Styles)XmlUtils.unmarshalString(styles_basedOn_Normal) );
// Use our style!
List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", true);
PPr ppr = Context.getWmlObjectFactory().createPPr();
((P)xpathResults.get(0)).setPPr(ppr);
PStyle ps = Context.getWmlObjectFactory().createPPrBasePStyle();
ps.setVal("testStyle");
ppr.setPStyle(ps);
setSetting(wordMLPackage, OVERRIDE);
wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
ParagraphStylesInTableFix.process(wordMLPackage);
// // Revert style and save:
// ppr.setPStyle(ps); // doesn't work - wrong ref!
// wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
Style ours = null;
for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) {
if ("testStyle-TableNormal-BR".equals(s.getStyleId())) {
ours = s;
break;
}
}
// Style s = getStyle(wordMLPackage, STYLE_NAME);
this.assertSz(ours, EXPECTED_RESULT);
}