Java Code Examples for org.docx4j.wml.PPr#setPStyle()
The following examples show how to use
org.docx4j.wml.PPr#setPStyle() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PStyle12PtInTableGridOverrideTrueTest.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
@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); }
Example 2
Source File: PStyle12PtInTableGridOverrideTrueTest.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
@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); }
Example 3
Source File: PStyle12PtInTableNormalOverrideFalseTest.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
@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); }
Example 4
Source File: PStyle12PtInTableGridOverrideFalseTest.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
@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); }
Example 5
Source File: PStyle12PtInTableGridOverrideFalseTest.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
@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); }
Example 6
Source File: PStyle11PtInTableOverrideTrueTest.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
@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); }
Example 7
Source File: PStyle11PtInTableOverrideTrueTest.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
@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); }
Example 8
Source File: PStyle11PtInTableOverrideFalseTest.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
@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); }
Example 9
Source File: PStyle11PtInTableOverrideFalseTest.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
@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); }
Example 10
Source File: PStyle12PtInTableNormalOverrideTrueTest.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
@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); }
Example 11
Source File: PStyle12PtInTableNormalOverrideFalseTest.java From docx4j-export-FO with Apache License 2.0 | 4 votes |
@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); }
Example 12
Source File: PStyle12PtInTableNormalOverrideTrueTest.java From docx4j-export-FO with Apache License 2.0 | 4 votes |
@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); }