/** * Compares the names of the Styles * @param compStyle */ public bool HasSameName(XWPFStyle compStyle) { CT_Style ctCompStyle = compStyle.GetCTStyle(); String name = ctCompStyle.name.val; return(name.Equals(ctStyle.name.val)); }
public void TestType() { CT_Style ctStyle = new CT_Style(); XWPFStyle style = new XWPFStyle(ctStyle); style.StyleType = ST_StyleType.paragraph; Assert.AreEqual(ST_StyleType.paragraph, style.StyleType); }
public void TestAddStylesToDocument() { XWPFDocument docOut = new XWPFDocument(); XWPFStyles styles = docOut.CreateStyles(); String strStyleName = "headline1"; CT_Style ctStyle = new CT_Style(); ctStyle.styleId = (strStyleName); XWPFStyle s = new XWPFStyle(ctStyle); styles.AddStyle(s); XWPFDocument docIn = XWPFTestDataSamples.WriteOutAndReadBack(docOut); styles = docIn.GetStyles(); Assert.IsTrue(styles.StyleExist(strStyleName)); }
public void TestSetStyles_Bug57254() { XWPFDocument docOut = new XWPFDocument(); XWPFStyles styles = docOut.CreateStyles(); CT_Styles ctStyles = new CT_Styles(); String strStyleId = "headline1"; CT_Style ctStyle = ctStyles.AddNewStyle(); ctStyle.styleId = (/*setter*/ strStyleId); styles.SetStyles(ctStyles); Assert.IsTrue(styles.StyleExist(strStyleId)); XWPFDocument docIn = XWPFTestDataSamples.WriteOutAndReadBack(docOut); styles = docIn.GetStyles(); Assert.IsTrue(styles.StyleExist(strStyleId)); }
private void WriteStylesheet() { CT_RPr rPr = new CT_RPr { RFonts = new CT_Fonts { Ascii_Attr = "Times New Roman", EastAsia_Attr = "Times New Roman", HAnsi_Attr = "Times New Roman", Cs_Attr = "Times New Roman" } }; CT_DocDefaults docDefaults = new CT_DocDefaults { RPrDefault = new CT_RPrDefault { RPr = rPr } }; CT_Style item = new CT_Style { Name = new CT_String { Val_Attr = "EmptyCellLayoutStyle" }, BasedOn = new CT_String { Val_Attr = "Normal" }, RPr = new CT_RPr { Sz = new CT_HpsMeasure { Val_Attr = 2.ToString(CultureInfo.InvariantCulture) } } }; StylesPart stylesPart = new StylesPart(); ((CT_Styles)stylesPart.Root).DocDefaults = docDefaults; ((CT_Styles)stylesPart.Root).Style.Add(item); _manager.WriteStaticPart(stylesPart, "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", "word/styles.xml", _manager.GetRootPart()); }
/// <summary> /// 加入标题定义 /// </summary> /// <param name="docxDocument"></param> /// <param name="strStyleId"></param> /// <param name="headingLevel"></param> private static void addCustomHeadingStyle(XWPFDocument docxDocument, String strStyleId, int headingLevel) { CT_Style ctStyle = new CT_Style(); ctStyle.styleId = strStyleId; CT_String styleName = new CT_String(); styleName.val = strStyleId; ctStyle.name = styleName; CT_DecimalNumber indentNumber = new CT_DecimalNumber(); indentNumber.val = BigInteger.ValueOf(headingLevel).ToString(); // lower number > style is more prominent in the formats bar ctStyle.uiPriority = indentNumber; CT_OnOff onoffnull = new CT_OnOff(); ctStyle.unhideWhenUsed = onoffnull; // style shows up in the formats bar ctStyle.qFormat = onoffnull; // style defines a heading of the given level CT_PPr ppr = new CT_PPr(); ppr.outlineLvl = indentNumber; ctStyle.pPr = ppr; XWPFStyle style = new XWPFStyle(ctStyle); // is a null op if already defined XWPFStyles styles = docxDocument.CreateStyles(); style.StyleType = ST_StyleType.paragraph; if (styles.GetStyle(strStyleId) == null) { styles.AddStyle(style); } }
public void AddCustomHeadingStyle(string name, int headingLevel, int outlineLevel, int ptSize = 12) { CT_Style ctStyle = ctStyles.AddNewStyle(); ctStyle.styleId = (name); CT_String styleName = new CT_String(); styleName.val = (name); ctStyle.name = (styleName); CT_DecimalNumber indentNumber = new CT_DecimalNumber(); indentNumber.val = headingLevel.ToString(); // lower number > style is more prominent in the formats bar ctStyle.uiPriority = (indentNumber); CT_OnOff onoffnull = new CT_OnOff(); ctStyle.unhideWhenUsed = (onoffnull); // style shows up in the formats bar ctStyle.qFormat = (onoffnull); // style defines a heading of the given level CT_PPr ppr = new CT_PPr(); ppr.outlineLvl = new CT_DecimalNumber() { val = outlineLevel.ToString() }; ctStyle.pPr = (ppr); CT_RPr rpr = new CT_RPr(); rpr.AddNewSz().val = (ulong)ptSize * 2; ctStyle.rPr = rpr; }
/** * Set style * @param style */ public void SetStyle(CT_Style style) { this.ctStyle = style; }
/** * constructor * @param style * @param styles */ public XWPFStyle(CT_Style style, XWPFStyles styles) { this.ctStyle = style; this.styles = styles; }
/** * constructor * @param style */ public XWPFStyle(CT_Style style) : this(style, null) { }
public static CT_Style Parse(XmlNode node, XmlNamespaceManager namespaceManager) { if (node == null) return null; CT_Style ctObj = new CT_Style(); if (node.Attributes["m:val"] != null) ctObj.val = (ST_Style)Enum.Parse(typeof(ST_Style), node.Attributes["m:val"].Value); return ctObj; }