public void SetText(XSSFRichTextString str) { XSSFWorkbook parent = (XSSFWorkbook)this.GetDrawing().GetParent().GetParent(); str.SetStylesTableReference(parent.GetStylesSource()); CT_TextParagraph ctTextParagraph = new CT_TextParagraph(); if (str.NumFormattingRuns == 0) { CT_RegularTextRun ctRegularTextRun = ctTextParagraph.AddNewR(); CT_TextCharacterProperties characterProperties = ctRegularTextRun.AddNewRPr(); characterProperties.lang = "en-US"; characterProperties.sz = 1100; ctRegularTextRun.t = str.String; } else { for (int index = 0; index < str.GetCTRst().sizeOfRArray(); ++index) { CT_RElt rarray = str.GetCTRst().GetRArray(index); CT_RPrElt pr = rarray.rPr ?? rarray.AddNewRPr(); CT_RegularTextRun ctRegularTextRun = ctTextParagraph.AddNewR(); CT_TextCharacterProperties rPr = ctRegularTextRun.AddNewRPr(); rPr.lang = "en-US"; XSSFSimpleShape.ApplyAttributes(pr, rPr); ctRegularTextRun.t = rarray.t; } } this.ctShape.txBody.SetPArray(new CT_TextParagraph[1] { ctTextParagraph }); }
/** * Add a new run of text * * @return a new run of text */ public XSSFTextRun AddNewTextRun() { CT_RegularTextRun r = _p.AddNewR(); CT_TextCharacterProperties rPr = r.AddNewRPr(); rPr.lang = ("en-US"); XSSFTextRun run = new XSSFTextRun(r, this); _Runs.Add(run); return(run); }
XSSFTextParagraph(CT_TextParagraph p, CT_Shape ctShape) { _p = p; _shape = ctShape; _Runs = new List <XSSFTextRun>(); foreach (object ch in _p.r) { if (ch is CT_RegularTextRun) { CT_RegularTextRun r = (CT_RegularTextRun)ch; _Runs.Add(new XSSFTextRun(r, this)); } else if (ch is CT_TextLineBreak) { CT_TextLineBreak br = (CT_TextLineBreak)ch; CT_RegularTextRun r = new CT_RegularTextRun(); r.rPr = (br.rPr); r.t = ("\n"); _Runs.Add(new XSSFTextRun(r, this)); } else if (ch is CT_TextField) { CT_TextField f = (CT_TextField)ch; CT_RegularTextRun r = new CT_RegularTextRun(); r.rPr = (f.rPr); r.t = (f.t); _Runs.Add(new XSSFTextRun(r, this)); } } //foreach(XmlObject ch in _p.selectPath("*")){ // if(ch is CTRegularTextRun){ // CTRegularTextRun r = (CTRegularTextRun)ch; // _Runs.add(new XSSFTextRun(r, this)); // } else if (ch is CTTextLineBreak){ // CTTextLineBreak br = (CTTextLineBreak)ch; // CTRegularTextRun r = CTRegularTextRun.Factory.newInstance(); // r.SetRPr(br.GetRPr()); // r.SetT("\n"); // _Runs.add(new XSSFTextRun(r, this)); // } else if (ch is CTTextField){ // CTTextField f = (CTTextField)ch; // CTRegularTextRun r = CTRegularTextRun.Factory.newInstance(); // r.SetRPr(f.GetRPr()); // r.SetT(f.GetT()); // _Runs.add(new XSSFTextRun(r, this)); // } //} }
/** * Insert a line break * * @return text run representing this line break ('\n') */ public XSSFTextRun AddLineBreak() { CT_TextLineBreak br = _p.AddNewBr(); CT_TextCharacterProperties brProps = br.AddNewRPr(); if (_Runs.Count > 0) { // by default line break has the font size of the last text run CT_TextCharacterProperties prevRun = _Runs[_Runs.Count - 1].GetRPr(); brProps = (prevRun); } CT_RegularTextRun r = new CT_RegularTextRun(); r.rPr = (brProps); r.t = ("\n"); XSSFTextRun run = new XSSFLineBreak(r, this, brProps); _Runs.Add(run); return(run); }
/** * Add a new paragraph run to this shape, Set to the provided rich text string * * @return Created paragraph run */ public XSSFTextParagraph AddNewTextParagraph(XSSFRichTextString str) { NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_TextBody txBody = ctShape.txBody; CT_TextParagraph p = txBody.AddNewP(); if (str.NumFormattingRuns == 0) { CT_RegularTextRun r = p.AddNewR(); CT_TextCharacterProperties rPr = r.AddNewRPr(); rPr.lang = (/*setter*/ "en-US"); rPr.sz = (/*setter*/ 1100); r.t = (/*setter*/ str.String); } else { for (int i = 0; i < str.GetCTRst().SizeOfRArray(); i++) { CT_RElt lt = str.GetCTRst().GetRArray(i); CT_RPrElt ltPr = lt.rPr; if (ltPr == null) { ltPr = lt.AddNewRPr(); } CT_RegularTextRun r = p.AddNewR(); CT_TextCharacterProperties rPr = r.AddNewRPr(); rPr.lang = (/*setter*/ "en-US"); ApplyAttributes(ltPr, rPr); r.t = (/*setter*/ lt.t); } } // Note: the XSSFTextParagraph constructor will create its required XSSFTextRuns from the provided CTTextParagraph XSSFTextParagraph paragraph = new XSSFTextParagraph(p, ctShape); _paragraphs.Add(paragraph); return(paragraph); }
/** * Set a single paragraph of text on the shape. Note this will replace all existing paragraphs Created on the shape. * @param str rich text string representing the paragraph text */ public void SetText(XSSFRichTextString str) { XSSFWorkbook wb = (XSSFWorkbook)GetDrawing().GetParent().GetParent(); str.SetStylesTableReference(wb.GetStylesSource()); CT_TextParagraph p = new CT_TextParagraph(); if (str.NumFormattingRuns == 0) { CT_RegularTextRun r = p.AddNewR(); CT_TextCharacterProperties rPr = r.AddNewRPr(); rPr.lang = (/*setter*/ "en-US"); rPr.sz = (/*setter*/ 1100); r.t = (/*setter*/ str.String); } else { for (int i = 0; i < str.GetCTRst().SizeOfRArray(); i++) { CT_RElt lt = str.GetCTRst().GetRArray(i); CT_RPrElt ltPr = lt.rPr; if (ltPr == null) { ltPr = lt.AddNewRPr(); } CT_RegularTextRun r = p.AddNewR(); CT_TextCharacterProperties rPr = r.AddNewRPr(); rPr.lang = (/*setter*/ "en-US"); ApplyAttributes(ltPr, rPr); r.t = (/*setter*/ lt.t); } } ClearText(); ctShape.txBody.SetPArray(new CT_TextParagraph[] { p }); _paragraphs.Add(new XSSFTextParagraph(ctShape.txBody.GetPArray(0), ctShape)); }
public XSSFTextRun(CT_RegularTextRun r, XSSFTextParagraph p) { _r = r; _p = p; }
public XSSFLineBreak(CT_RegularTextRun r, XSSFTextParagraph p, CT_TextCharacterProperties brProps) : base(r, p) { _brProps = brProps; }
/** * Sets the title text. */ public void SetTitle(string newTitle) { CT_Title ctTitle; if (chart.IsSetTitle()) { ctTitle = chart.title; } else { ctTitle = chart.AddNewTitle(); } CT_Tx tx; if (ctTitle.IsSetTx()) { tx = ctTitle.tx; } else { tx = ctTitle.AddNewTx(); } if (tx.IsSetStrRef()) { tx.UnsetStrRef(); } OpenXmlFormats.Dml.Chart.CT_TextBody rich; if (tx.IsSetRich()) { rich = tx.rich; } else { rich = tx.AddNewRich(); rich.AddNewBodyPr(); // body properties must exist (but can be empty) } CT_TextParagraph para; if (rich.SizeOfPArray() > 0) { para = rich.GetPArray(0); } else { para = rich.AddNewP(); } if (para.SizeOfRArray() > 0) { CT_RegularTextRun run = para.GetRArray(0); run.t = (newTitle); } else if (para.SizeOfFldArray() > 0) { OpenXmlFormats.Dml.CT_TextField fld = para.GetFldArray(0); fld.t = (newTitle); } else { CT_RegularTextRun run = para.AddNewR(); run.t = (newTitle); } }