public static XSSFRichTextString CreateRichTextString(string text, IFont font) { var richText = new XSSFRichTextString(text); richText.ApplyFont(font); return(richText); }
public void TestClearFormatting() { XSSFRichTextString rt = new XSSFRichTextString("Apache POI"); Assert.AreEqual("Apache POI", rt.String); Assert.AreEqual(false, rt.HasFormatting()); rt.ClearFormatting(); CT_Rst st = rt.GetCTRst(); Assert.IsTrue(st.IsSetT()); Assert.AreEqual("Apache POI", rt.String); Assert.AreEqual(0, rt.NumFormattingRuns); Assert.AreEqual(false, rt.HasFormatting()); XSSFFont font = new XSSFFont(); font.IsBold = true; rt.ApplyFont(7, 10, font); Assert.AreEqual(2, rt.NumFormattingRuns); Assert.AreEqual(true, rt.HasFormatting()); rt.ClearFormatting(); Assert.AreEqual("Apache POI", rt.String); Assert.AreEqual(0, rt.NumFormattingRuns); Assert.AreEqual(false, rt.HasFormatting()); }
public void TestGetFonts() { XSSFRichTextString rt = new XSSFRichTextString(); XSSFFont font1 = new XSSFFont(); font1.FontName = ("Arial"); font1.IsItalic = (true); rt.Append("The quick", font1); XSSFFont font1FR = (XSSFFont)rt.GetFontOfFormattingRun(0); Assert.AreEqual(font1.IsItalic, font1FR.IsItalic); Assert.AreEqual(font1.FontName, font1FR.FontName); XSSFFont font2 = new XSSFFont(); font2.FontName = ("Courier"); font2.IsBold = (true); rt.Append(" brown fox", font2); XSSFFont font2FR = (XSSFFont)rt.GetFontOfFormattingRun(1); Assert.AreEqual(font2.IsBold, font2FR.IsBold); Assert.AreEqual(font2.FontName, font2FR.FontName); }
public void TestRichText() { XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = wb.CreateSheet() as XSSFSheet; XSSFDrawing Drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing; XSSFTextBox shape = Drawing.CreateTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4)) as XSSFTextBox; XSSFRichTextString rt = new XSSFRichTextString("Test String"); XSSFFont font = wb.CreateFont() as XSSFFont; font.SetColor(new XSSFColor(Color.FromRgb(0, 128, 128))); font.IsItalic = (true); font.IsBold = (true); font.Underline = FontUnderlineType.Single; rt.ApplyFont(font); shape.SetText(rt); CT_TextParagraph pr = shape.GetCTShape().txBody.p[0]; Assert.AreEqual(1, pr.SizeOfRArray()); CT_TextCharacterProperties rPr = pr.r[0].rPr; Assert.AreEqual(true, rPr.b); Assert.AreEqual(true, rPr.i); Assert.AreEqual(ST_TextUnderlineType.sng, rPr.u); Assert.IsTrue(Arrays.Equals( new byte[] { 0, (byte)128, (byte)128 }, rPr.solidFill.srgbClr.val)); checkRewrite(wb); wb.Close(); }
public void TestBug57294() { IWorkbook wb = SXSSFITestDataProvider.instance.CreateWorkbook(); ISheet sheet = wb.CreateSheet(); IRow row = sheet.CreateRow(0); ICell cell = row.CreateCell(0); IRichTextString str = new XSSFRichTextString("Test rich text string"); str.ApplyFont(2, 4, (short)0); Assert.AreEqual(3, str.NumFormattingRuns); cell.SetCellValue(str); IWorkbook wbBack = SXSSFITestDataProvider.instance.WriteOutAndReadBack(wb); wb.Close(); // re-read after serializing and reading back ICell cellBack = wbBack.GetSheetAt(0).GetRow(0).GetCell(0); Assert.IsNotNull(cellBack); IRichTextString strBack = cellBack.RichStringCellValue; Assert.IsNotNull(strBack); Assert.AreEqual(3, strBack.NumFormattingRuns); Assert.AreEqual(0, strBack.GetIndexOfFormattingRun(0)); Assert.AreEqual(2, strBack.GetIndexOfFormattingRun(1)); Assert.AreEqual(4, strBack.GetIndexOfFormattingRun(2)); wbBack.Close(); }
public void TestRichTextFontAndColor() { XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = wb.CreateSheet() as XSSFSheet; XSSFDrawing Drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing; XSSFTextBox shape = Drawing.CreateTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4)) as XSSFTextBox; XSSFRichTextString rt = new XSSFRichTextString("Test String"); XSSFFont font = wb.CreateFont() as XSSFFont; font.SetColor(new XSSFColor(Color.FromRgb(0, 128, 128))); font.FontName = ("Arial"); rt.ApplyFont(font); shape.SetText(rt); CT_TextParagraph pr = shape.GetCTShape().txBody.GetPArray(0); Assert.AreEqual(1, pr.SizeOfRArray()); CT_TextCharacterProperties rPr = pr.GetRArray(0).rPr; Assert.AreEqual("Arial", rPr.latin.typeface); Assert.IsTrue(Arrays.Equals( new byte[] { 0, (byte)128, (byte)128 }, rPr.solidFill.srgbClr.val)); checkRewrite(wb); wb.Close(); }
public void SetCellValue(IRichTextString value) { XSSFRichTextString xvalue = (XSSFRichTextString)value; if (xvalue != null && xvalue.String != null) { EnsureRichTextStringType(); if (xvalue.Length > SpreadsheetVersion.EXCEL2007.MaxTextLength) { throw new InvalidOperationException("The maximum length of cell contents (text) is 32,767 characters"); } if (xvalue.HasFormatting()) { logger.Log(POILogger.WARN, "SXSSF doesn't support Shared Strings, rich text formatting information has be lost"); } ((RichTextValue)_value).Value = xvalue; } else { SetCellType(CellType.Blank); } }
private Dictionary <short, List <string> > AnalysisCellString(XSSFCell cell) { Dictionary <short, List <string> > _cellList = new Dictionary <short, List <string> >(); XSSFRichTextString rich = (XSSFRichTextString)cell.RichStringCellValue; int formattingRuns = cell.RichStringCellValue.NumFormattingRuns; for (int i = 0; i < formattingRuns; i++) { int startIdx = rich.GetIndexOfFormattingRun(i); int length = rich.GetLengthOfFormattingRun(i); string st = rich.String.Substring(startIdx, length); IFont font; if (i == 0) { short fontIndex = cell.CellStyle.FontIndex; font = _workBook.GetFontAt(fontIndex); } else { font = rich.GetFontOfFormattingRun(i); } if (_cellList.Keys.Where(t => t == font.Color).Count() == 0) { _cellList.Add(font.Color, new List <string>() { st }); } else { _cellList[font.Color].Add(st); } } return(_cellList); }
public void SetString() { XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sh = (XSSFSheet)wb.CreateSheet(); XSSFComment comment = (XSSFComment)sh.CreateDrawingPatriarch().CreateCellComment(new XSSFClientAnchor()); //passing HSSFRichTextString is incorrect try { comment.String = (new HSSFRichTextString(TEST_RICHTEXTSTRING)); Assert.Fail("expected exception"); } catch (ArgumentException e) { Assert.AreEqual("Only XSSFRichTextString argument is supported", e.Message); } //simple string argument comment.SetString(TEST_RICHTEXTSTRING); Assert.AreEqual(TEST_RICHTEXTSTRING, comment.String.String); //if the text is already Set, it should be overridden, not Added twice! comment.SetString(TEST_RICHTEXTSTRING); CT_Comment ctComment = comment.GetCTComment(); // Assert.Fail("TODO test case incomplete!?"); //XmlObject[] obj = ctComment.selectPath( // "declare namespace w='"+XSSFRelation.NS_SPREADSHEETML+"' .//w:text"); //Assert.AreEqual(1, obj.Length); Assert.AreEqual(TEST_RICHTEXTSTRING, comment.String.String); //sequential call of comment.String should return the same XSSFRichTextString object Assert.AreSame(comment.String, comment.String); XSSFRichTextString richText = new XSSFRichTextString(TEST_RICHTEXTSTRING); XSSFFont font1 = (XSSFFont)wb.CreateFont(); font1.FontName = ("Tahoma"); font1.FontHeightInPoints = 8.5; font1.IsItalic = true; font1.Color = IndexedColors.BlueGrey.Index; richText.ApplyFont(0, 5, font1); //check the low-level stuff comment.String = richText; //obj = ctComment.selectPath( // "declare namespace w='"+XSSFRelation.NS_SPREADSHEETML+"' .//w:text"); //Assert.AreEqual(1, obj.Length); Assert.AreSame(comment.String, richText); //check that the rich text is Set in the comment CT_RPrElt rPr = richText.GetCTRst().GetRArray(0).rPr; Assert.AreEqual(true, rPr.GetIArray(0).val); Assert.AreEqual(8.5, rPr.GetSzArray(0).val); Assert.AreEqual(IndexedColors.BlueGrey.Index, (short)rPr.GetColorArray(0).indexed); Assert.AreEqual("Tahoma", rPr.GetRFontArray(0).val); Assert.IsNotNull(XSSFTestDataSamples.WriteOutAndReadBack(wb)); }
public void Test47278() { XSSFWorkbook wb = (XSSFWorkbook)_testDataProvider.CreateWorkbook(); XSSFSheet sheet = (XSSFSheet)wb.CreateSheet(); IRow row = sheet.CreateRow(0); SharedStringsTable sst = wb.GetSharedStringSource(); Assert.AreEqual(0, sst.Count); //case 1. cell.SetCellValue(new XSSFRichTextString((String)null)); ICell cell_0 = row.CreateCell(0); XSSFRichTextString str = new XSSFRichTextString((String)null); Assert.IsNull(str.String); cell_0.SetCellValue(str); Assert.AreEqual(0, sst.Count); Assert.AreEqual(CellType.Blank, cell_0.CellType); //case 2. cell.SetCellValue((String)null); ICell cell_1 = row.CreateCell(1); cell_1.SetCellValue((String)null); Assert.AreEqual(0, sst.Count); Assert.AreEqual(CellType.Blank, cell_1.CellType); }
public void TestApplyFont_usermodel() { String text = "Apache Software Foundation"; XSSFRichTextString str = new XSSFRichTextString(text); XSSFFont font1 = new XSSFFont(); XSSFFont font2 = new XSSFFont(); XSSFFont font3 = new XSSFFont(); str.ApplyFont(font1); Assert.AreEqual(1, str.NumFormattingRuns); str.ApplyFont(0, 6, font1); str.ApplyFont(6, text.Length, font2); Assert.AreEqual(2, str.NumFormattingRuns); Assert.AreEqual("Apache", str.GetCTRst().GetRArray(0).t); Assert.AreEqual(" Software Foundation", str.GetCTRst().GetRArray(1).t); str.ApplyFont(15, 26, font3); Assert.AreEqual(3, str.NumFormattingRuns); Assert.AreEqual("Apache", str.GetCTRst().GetRArray(0).t); Assert.AreEqual(" Software", str.GetCTRst().GetRArray(1).t); Assert.AreEqual(" Foundation", str.GetCTRst().GetRArray(2).t); str.ApplyFont(6, text.Length, font2); Assert.AreEqual(2, str.NumFormattingRuns); Assert.AreEqual("Apache", str.GetCTRst().GetRArray(0).t); Assert.AreEqual(" Software Foundation", str.GetCTRst().GetRArray(1).t); }
public void TestEmpty() { XSSFRichTextString rt = new XSSFRichTextString(); Assert.AreEqual(0, rt.GetIndexOfFormattingRun(9999)); Assert.AreEqual(-1, rt.GetLengthOfFormattingRun(9999)); Assert.IsNull(rt.GetFontAtIndex(9999)); }
static XSSFRichTextString style(string x, IFont index) { var text = new XSSFRichTextString(x); text.ApplyFont(0, x.Length, index); return(text); }
private IRichTextString BuildFormattedSessionCellContent(XSSFWorkbook workbook, ScheduleDetailDTO session) { string className = session.Schedule.Class.Name; string classBranch = className + " - " + session.Schedule.Branch; string song = "♪ " + session.Schedule.Song; string numberOfSessions = $"Buổi {session.SessionNo}/{session.Schedule.Sessions}"; XSSFFont classBranchFont = (XSSFFont)workbook.CreateFont(); classBranchFont.FontName = "Times New Roman"; classBranchFont.FontHeightInPoints = 18; classBranchFont.IsBold = true; if (session.SessionNo == 1) { classBranchFont.SetColor(new XSSFColor(new byte[] { 192, 0, 0 })); } IFont songFont = workbook.CreateFont(); songFont.FontName = "Times New Roman"; songFont.FontHeightInPoints = 18; songFont.IsBold = false; IRichTextString formattedCellContent; bool isYoga = string.Equals(className, "Yoga", StringComparison.CurrentCultureIgnoreCase); bool isCardioDance = string.Equals(className, "Cardio Dance", StringComparison.CurrentCultureIgnoreCase); if (isYoga || isCardioDance) { if (isYoga) { if (classBranch.Contains("Q3")) { classBranch += ", LVS"; } else if (classBranch.Contains("LVS")) { classBranch += ", Q3"; } } else { classBranch = className; } formattedCellContent = new XSSFRichTextString(classBranch); formattedCellContent.ApplyFont(0, classBranch.Length, classBranchFont); } else { formattedCellContent = new XSSFRichTextString(classBranch + "\n" + song + "\n" + numberOfSessions); formattedCellContent.ApplyFont(0, classBranch.Length, classBranchFont); formattedCellContent.ApplyFont(classBranch.Length + 1, (classBranch + "\n" + song).Length, songFont); formattedCellContent.ApplyFont((classBranch + "\n" + song).Length + 1, (classBranch + "\n" + song + "\n" + numberOfSessions).Length, classBranchFont); } return(formattedCellContent); }
public void TestApplyFontIndex() { XSSFRichTextString rt = new XSSFRichTextString("Apache POI"); rt.ApplyFont(0, 10, (short)1); rt.ApplyFont((short)1); Assert.IsNotNull(rt.GetFontAtIndex(0)); }
public void TestToString() { XSSFRichTextString rt = new XSSFRichTextString("Apache POI"); Assert.IsNotNull(rt.ToString()); // TODO: normally ToString() should never return null, should we adjust this? rt = new XSSFRichTextString(); Assert.IsNull(rt.ToString()); }
public void TestUtfDecode() { CT_Rst st = new CT_Rst(); st.t = ("abc_x000D_2ef_x000D_"); XSSFRichTextString rt = new XSSFRichTextString(st); //_x000D_ is Converted into carriage return Assert.AreEqual("abc\r2ef\r", rt.String); }
private void CreateRow(ISheet sheet, int rowNum, ICellStyle cellStyle, XSSFFont commentFont, List <ISegmentElement> sourceSegment, List <ISegmentElement> targetSegment, params string[] values) { IRow row = sheet.CreateRow(rowNum); int i; for (i = 0; i < values.Length; i++) { ICell cell = row.CreateCell(i); cell.SetCellValue(values[i] ?? string.Empty); cell.CellStyle = cellStyle; } if (sourceSegment != null) { ICell cell2 = row.CreateCell(i); cell2.CellStyle = cellStyle; XSSFRichTextString xSSFRichTextString = new XSSFRichTextString(""); foreach (ISegmentElement current in sourceSegment) { if (current is CommentElement) { xSSFRichTextString.Append(current.Value, commentFont); } else { xSSFRichTextString.Append(current.Value, InlineRegularFont); } } cell2.SetCellValue(xSSFRichTextString); i++; } if (targetSegment != null) { ICell cell3 = row.CreateCell(i); cell3.CellStyle = cellStyle; XSSFRichTextString xSSFRichTextString2 = new XSSFRichTextString(""); foreach (ISegmentElement current2 in targetSegment) { if (current2 is CommentElement) { xSSFRichTextString2.Append(current2.Value, commentFont); } else { xSSFRichTextString2.Append(current2.Value, InlineRegularFont); } } cell3.SetCellValue(xSSFRichTextString2); } }
public void TestRgbColor() { const string testText = "Apache"; XSSFRichTextString rt = new XSSFRichTextString(testText); XSSFFont font = new XSSFFont { FontName = "Times New Roman", FontHeightInPoints = 11 }; font.SetColor(new XSSFColor(Color.Red)); rt.ApplyFont(0, testText.Length, font); CT_Rst ct = rt.GetCTRst(); Assert.AreEqual("<r><rPr><color rgb=\"FF0000\"/><rFont val=\"Times New Roman\"/><sz val=\"11\"/></rPr><t>Apache</t></r>", ct.XmlText); }
public void TestNewChart() { IWorkbook wb = CreateWorkbookWithChart(); XSSFChart chart = GetChartFromWorkbook(wb, "linechart"); Assert.IsNotNull(chart); Assert.IsNull(chart.Title); String myTitle = "My chart title"; chart.SetTitle(myTitle); XSSFRichTextString queryTitle = chart.Title; Assert.IsNotNull(queryTitle); Assert.AreEqual(myTitle, queryTitle.ToString()); }
public void TestExistingChartNoTitle() { IWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("chartTitle_noTitle.xlsx"); XSSFChart chart = GetChartFromWorkbook(wb, "Sheet1"); Assert.IsNotNull(chart); Assert.IsNull(chart.Title); String myTitle = "My chart title"; chart.SetTitle(myTitle); XSSFRichTextString queryTitle = chart.Title; Assert.IsNotNull(queryTitle); Assert.AreEqual(myTitle, queryTitle.ToString()); }
/** * make sure we insert xml:space="preserve" attribute * if a string has leading or trailing white spaces */ public void TestPreserveSpaces() { XSSFRichTextString rt = new XSSFRichTextString("Apache"); CT_Rst ct = rt.GetCTRst(); string t = ct.t; Assert.AreEqual("<t>Apache</t>", ct.XmlText); rt.String = " Apache"; Assert.AreEqual("<t xml:space=\"preserve\"> Apache</t>", ct.XmlText); rt.Append(" POI"); rt.Append(" "); Assert.AreEqual(" Apache POI ", rt.String); //Assert.AreEqual("<xml-fragment xml:space=\"preserve\"> Apache</t>", rt.GetCTRst().GetRArray(0).xmlText()); //Assert.AreEqual("<xml-fragment xml:space=\"preserve\"> POI</xml-fragment>", rt.getCTRst().getRArray(1).xgetT().xmlText()); //Assert.AreEqual("<xml-fragment xml:space=\"preserve\"> </xml-fragment>", rt.getCTRst().getRArray(2).xgetT().xmlText()); }
public void TestCreate() { XSSFRichTextString rt = new XSSFRichTextString("Apache POI"); Assert.AreEqual("Apache POI", rt.String); Assert.AreEqual(false, rt.HasFormatting()); CT_Rst st = rt.GetCTRst(); Assert.IsTrue(st.IsSetT()); Assert.AreEqual("Apache POI", st.t); Assert.AreEqual(false, rt.HasFormatting()); rt.Append(" is cool stuff"); Assert.AreEqual(2, st.sizeOfRArray()); Assert.IsFalse(st.IsSetT()); Assert.AreEqual("Apache POI is cool stuff", rt.String); Assert.AreEqual(false, rt.HasFormatting()); }
public void Test59008Font() { XSSFFont font = new XSSFFont(new CT_Font()); XSSFRichTextString rts = new XSSFRichTextString(); rts.Append("This is correct "); int s1 = rts.Length; rts.Append("This is Bold Red", font); int s2 = rts.Length; rts.Append(" This uses the default font rather than the cell style font"); int s3 = rts.Length; //Assert.AreEqual("<xml-fragment/>", rts.GetFontAtIndex(s1 - 1).ToString()); Assert.AreEqual("<font></font>", rts.GetFontAtIndex(s1 - 1).ToString()); Assert.AreEqual(font, rts.GetFontAtIndex(s2 - 1)); //Assert.AreEqual("<xml-fragment/>", rts.GetFontAtIndex(s3 - 1).ToString()); Assert.AreEqual("<font></font>", rts.GetFontAtIndex(s3 - 1).ToString()); }
private void AnalysisCellString(XSSFCell cell) { XSSFRichTextString rich = (XSSFRichTextString)cell.RichStringCellValue; string st2 = rich.String; int formattingRuns = cell.RichStringCellValue.NumFormattingRuns; if (formattingRuns > 0) { st2 = string.Empty; } XSSFFont font = (XSSFFont)_workBook.CreateFont(); for (int i = 0; i < formattingRuns; i++) { int startIdx = rich.GetIndexOfFormattingRun(i); int length = rich.GetLengthOfFormattingRun(i); string st = rich.String.Substring(startIdx, length); if (i == 0) { short fontIndex = cell.CellStyle.FontIndex; font = (XSSFFont)_workBook.GetFontAt(fontIndex); } else { font = (XSSFFont)rich.GetFontOfFormattingRun(i); } if (font.Color != IndexedColors.White.Index && font.Color != 0) { st2 += st; } } font.Color = IndexedColors.Black.Index; XSSFRichTextString rich2 = new XSSFRichTextString(); rich2.Append(st2, font); cell.SetCellValue(rich2); }
public void TestApplyFontWithStyles() { XSSFRichTextString rt = new XSSFRichTextString("Apache POI"); StylesTable tbl = new StylesTable(); rt.SetStylesTableReference(tbl); try { rt.ApplyFont(0, 10, (short)1); Assert.Fail("Fails without styles in the table"); } catch (ArgumentOutOfRangeException) { // expected } tbl.PutFont(new XSSFFont()); rt.ApplyFont(0, 10, (short)1); rt.ApplyFont((short)1); }
public void TestBug56511_values() { XSSFWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("56511.xlsx"); ISheet sheet = wb.GetSheetAt(0); IRow row = sheet.GetRow(0); // verify the values to ensure future Changes keep the returned information equal XSSFRichTextString rt = (XSSFRichTextString)row.GetCell(0).RichStringCellValue; Assert.AreEqual(0, rt.NumFormattingRuns); Assert.IsNull(rt.GetFontOfFormattingRun(0)); Assert.AreEqual(-1, rt.GetLengthOfFormattingRun(0)); rt = (XSSFRichTextString)row.GetCell(1).RichStringCellValue; Assert.AreEqual(0, row.GetCell(1).RichStringCellValue.NumFormattingRuns); Assert.IsNull(rt.GetFontOfFormattingRun(1)); Assert.AreEqual(-1, rt.GetLengthOfFormattingRun(1)); rt = (XSSFRichTextString)row.GetCell(2).RichStringCellValue; Assert.AreEqual(2, rt.NumFormattingRuns); Assert.IsNotNull(rt.GetFontOfFormattingRun(0)); Assert.AreEqual(4, rt.GetLengthOfFormattingRun(0)); Assert.IsNotNull(rt.GetFontOfFormattingRun(1)); Assert.AreEqual(9, rt.GetLengthOfFormattingRun(1)); Assert.IsNull(rt.GetFontOfFormattingRun(2)); rt = (XSSFRichTextString)row.GetCell(3).RichStringCellValue; Assert.AreEqual(3, rt.NumFormattingRuns); Assert.IsNull(rt.GetFontOfFormattingRun(0)); Assert.AreEqual(1, rt.GetLengthOfFormattingRun(0)); Assert.IsNotNull(rt.GetFontOfFormattingRun(1)); Assert.AreEqual(3, rt.GetLengthOfFormattingRun(1)); Assert.IsNotNull(rt.GetFontOfFormattingRun(2)); Assert.AreEqual(9, rt.GetLengthOfFormattingRun(2)); }
public void TestApplyFont() { XSSFRichTextString rt = new XSSFRichTextString(); rt.Append("123"); rt.Append("4567"); rt.Append("89"); Assert.AreEqual("123456789", rt.String); Assert.AreEqual(false, rt.HasFormatting()); XSSFFont font1 = new XSSFFont(); font1.IsBold = (true); rt.ApplyFont(2, 5, font1); Assert.AreEqual(true, rt.HasFormatting()); Assert.AreEqual(4, rt.NumFormattingRuns); Assert.AreEqual(0, rt.GetIndexOfFormattingRun(0)); Assert.AreEqual("12", rt.GetCTRst().GetRArray(0).t); Assert.AreEqual(2, rt.GetIndexOfFormattingRun(1)); Assert.AreEqual("345", rt.GetCTRst().GetRArray(1).t); Assert.AreEqual(5, rt.GetIndexOfFormattingRun(2)); Assert.AreEqual(2, rt.GetLengthOfFormattingRun(2)); Assert.AreEqual("67", rt.GetCTRst().GetRArray(2).t); Assert.AreEqual(7, rt.GetIndexOfFormattingRun(3)); Assert.AreEqual(2, rt.GetLengthOfFormattingRun(3)); Assert.AreEqual("89", rt.GetCTRst().GetRArray(3).t); Assert.AreEqual(-1, rt.GetIndexOfFormattingRun(9999)); Assert.AreEqual(-1, rt.GetLengthOfFormattingRun(9999)); Assert.IsNull(rt.GetFontAtIndex(9999)); }
public void TestSetTextSingleParagraph() { XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = wb.CreateSheet() as XSSFSheet; XSSFDrawing drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing; XSSFTextBox shape = drawing.CreateTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4)); XSSFRichTextString rt = new XSSFRichTextString("Test String"); XSSFFont font = wb.CreateFont() as XSSFFont; font.SetColor(new XSSFColor(Color.FromRgb(0, 255, 255))); font.FontName = ("Arial"); rt.ApplyFont(font); shape.SetText(rt); List <XSSFTextParagraph> paras = shape.TextParagraphs; Assert.AreEqual(1, paras.Count); Assert.AreEqual("Test String", paras[0].Text); List <XSSFTextRun> runs = paras[0].TextRuns; Assert.AreEqual(1, runs.Count); Assert.AreEqual("Arial", runs[0].FontFamily); var clr = runs[0].FontColor; Assert.IsTrue(Arrays.Equals( new int[] { 0, 255, 255 }, new int[] { clr.R, clr.G, clr.B })); checkRewrite(wb); wb.Close(); }
/// <summary> /// An Arrow bug from 2007+ version /// </summary> /// <param name="cell"></param> /// <param name="comment"></param> /// <param name="author"></param> public void AddCellComment(ICell cell, string comment, string author = "") { var patriach = cell.Sheet.CreateDrawingPatriarch(); IComment ccm; IRichTextString text; if (IsNewFormat) { var anchor = new XSSFClientAnchor(0, 0, 0, 0, cell.ColumnIndex, cell.RowIndex, cell.ColumnIndex + 4, cell.ColumnIndex + 4); ccm = patriach.CreateCellComment(anchor); text = new XSSFRichTextString(comment); } else { var anchor = new HSSFClientAnchor(0, 0, 0, 0, cell.ColumnIndex, cell.RowIndex, cell.ColumnIndex + 4, cell.ColumnIndex + 4); ccm = patriach.CreateCellComment(anchor); text = new HSSFRichTextString(comment); } ccm.String = text; ccm.Author = author; ccm.Visible = false; cell.CellComment = ccm; }