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); }
private static void CopyStyle(XWPFDocument srcDoc, XWPFDocument destDoc, XWPFStyle style) { if (destDoc == null || style == null) { return; } if (destDoc.GetCTStyle() == null) { destDoc.CreateStyles(); } List <XWPFStyle> usedStyleList = srcDoc.GetStyles().GetUsedStyleList(style); for (int i = 0; i < usedStyleList.Count; i++) { destDoc.GetStyles().AddStyle(usedStyleList[i]); } }
/// <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 TestAddStylesToDocument() { XWPFDocument docOut = new XWPFDocument(); XWPFStyles styles = docOut.CreateStyles(); String strStyleId = "headline1"; CT_Style ctStyle = new CT_Style(); ctStyle.styleId = (strStyleId); XWPFStyle s = new XWPFStyle(ctStyle); styles.AddStyle(s); Assert.IsTrue(styles.StyleExist(strStyleId)); XWPFDocument docIn = XWPFTestDataSamples.WriteOutAndReadBack(docOut); styles = docIn.GetStyles(); Assert.IsTrue(styles.StyleExist(strStyleId)); }
public void TestGetUsedStyles() { XWPFDocument sampleDoc = XWPFTestDataSamples.OpenSampleDocument("Styles.docx"); List <XWPFStyle> testUsedStyleList = new List <XWPFStyle>(); XWPFStyles styles = sampleDoc.GetStyles(); XWPFStyle style = styles.GetStyle("berschrift1"); testUsedStyleList.Add(style); testUsedStyleList.Add(styles.GetStyle("Standard")); testUsedStyleList.Add(styles.GetStyle("berschrift1Zchn")); testUsedStyleList.Add(styles.GetStyle("Absatz-Standardschriftart")); style.HasSameName(style); List <XWPFStyle> usedStyleList = styles.GetUsedStyleList(style); //Assert.AreEqual(usedStyleList, testUsedStyleList); Assert.AreEqual(usedStyleList.Count, testUsedStyleList.Count); for (int i = 0; i < usedStyleList.Count; i++) { Assert.AreEqual(usedStyleList[i], testUsedStyleList[i]); } }
private static void CopyStyle(this XWPFDocument srcDoc, XWPFDocument destDoc, XWPFStyle style) { if (destDoc == null || style == null) { return; } if (destDoc.GetStyles() == null) { destDoc.CreateStyles(); } foreach (var xwpfStyle in srcDoc.GetStyles().GetUsedStyleList(style)) { destDoc.GetStyles().AddStyle(xwpfStyle); } }