public void TestMultiRelationShips() { XSSFWorkbook wb = new XSSFWorkbook(); byte[] pic1Data = Encoding.UTF8.GetBytes("test jpeg data"); byte[] pic2Data = Encoding.UTF8.GetBytes("test png data"); List <XSSFPictureData> pictures = wb.GetAllPictures() as List <XSSFPictureData>; Assert.AreEqual(0, pictures.Count); int pic1 = wb.AddPicture(pic1Data, XSSFWorkbook.PICTURE_TYPE_JPEG); int pic2 = wb.AddPicture(pic2Data, XSSFWorkbook.PICTURE_TYPE_PNG); XSSFSheet sheet1 = wb.CreateSheet() as XSSFSheet; XSSFDrawing drawing1 = sheet1.CreateDrawingPatriarch() as XSSFDrawing; XSSFPicture shape1 = drawing1.CreatePicture(new XSSFClientAnchor(), pic1) as XSSFPicture; XSSFPicture shape2 = drawing1.CreatePicture(new XSSFClientAnchor(), pic2) as XSSFPicture; XSSFSheet sheet2 = wb.CreateSheet() as XSSFSheet; XSSFDrawing drawing2 = sheet2.CreateDrawingPatriarch() as XSSFDrawing; XSSFPicture shape3 = drawing2.CreatePicture(new XSSFClientAnchor(), pic2) as XSSFPicture; XSSFPicture shape4 = drawing2.CreatePicture(new XSSFClientAnchor(), pic1) as XSSFPicture; Assert.AreEqual(2, pictures.Count); wb = XSSFTestDataSamples.WriteOutAndReadBack(wb) as XSSFWorkbook; pictures = wb.GetAllPictures() as List <XSSFPictureData>; Assert.AreEqual(2, pictures.Count); sheet1 = wb.GetSheetAt(0) as XSSFSheet; drawing1 = sheet1.CreateDrawingPatriarch() as XSSFDrawing; XSSFPicture shape11 = (XSSFPicture)drawing1.GetShapes()[0]; Assert.IsTrue(Arrays.Equals(shape1.PictureData.Data, shape11.PictureData.Data)); XSSFPicture shape22 = (XSSFPicture)drawing1.GetShapes()[0]; Assert.IsTrue(Arrays.Equals(shape2.PictureData.Data, shape22.PictureData.Data)); sheet2 = wb.GetSheetAt(1) as XSSFSheet; drawing2 = sheet2.CreateDrawingPatriarch() as XSSFDrawing; XSSFPicture shape33 = (XSSFPicture)drawing2.GetShapes()[0]; Assert.IsTrue(Arrays.Equals(shape3.PictureData.Data, shape33.PictureData.Data)); XSSFPicture shape44 = (XSSFPicture)drawing2.GetShapes()[1]; Assert.IsTrue(Arrays.Equals(shape4.PictureData.Data, shape44.PictureData.Data)); }
public void TestReadAnchors() { XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = wb.CreateSheet() as XSSFSheet; XSSFDrawing Drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing; XSSFClientAnchor anchor1 = new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4); XSSFShape shape1 = Drawing.CreateTextbox(anchor1) as XSSFShape; Assert.IsNotNull(shape1); XSSFClientAnchor anchor2 = new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 5); XSSFShape shape2 = Drawing.CreateTextbox(anchor2) as XSSFShape; Assert.IsNotNull(shape2); int pictureIndex = wb.AddPicture(new byte[] { }, XSSFWorkbook.PICTURE_TYPE_PNG); XSSFClientAnchor anchor3 = new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 6); XSSFShape shape3 = Drawing.CreatePicture(anchor3, pictureIndex) as XSSFShape; Assert.IsNotNull(shape3); wb = XSSFTestDataSamples.WriteOutAndReadBack(wb) as XSSFWorkbook; sheet = wb.GetSheetAt(0) as XSSFSheet; Drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing; List <XSSFShape> shapes = Drawing.GetShapes(); Assert.AreEqual(3, shapes.Count); Assert.AreEqual(shapes[0].GetAnchor(), anchor1); Assert.AreEqual(shapes[1].GetAnchor(), anchor2); Assert.AreEqual(shapes[2].GetAnchor(), anchor3); Assert.IsNotNull(XSSFTestDataSamples.WriteOutAndReadBack(wb)); }
private void check58325(XSSFWorkbook wb, int expectedShapes) { XSSFSheet sheet = wb.GetSheet("MetasNM001") as XSSFSheet; Assert.IsNotNull(sheet); StringBuilder str = new StringBuilder(); str.Append("sheet " + sheet.SheetName + " - "); XSSFDrawing drawing = sheet.GetDrawingPatriarch(); //drawing = ((XSSFSheet)sheet).createDrawingPatriarch(); List <XSSFShape> shapes = drawing.GetShapes(); str.Append("drawing.Shapes.size() = " + shapes.Count); IEnumerator <XSSFShape> it = shapes.GetEnumerator(); while (it.MoveNext()) { XSSFShape shape = it.Current; str.Append(", " + shape.ToString()); str.Append(", Col1:" + ((XSSFClientAnchor)shape.GetAnchor()).Col1); str.Append(", Col2:" + ((XSSFClientAnchor)shape.GetAnchor()).Col2); str.Append(", Row1:" + ((XSSFClientAnchor)shape.GetAnchor()).Row1); str.Append(", Row2:" + ((XSSFClientAnchor)shape.GetAnchor()).Row2); } Assert.AreEqual(expectedShapes, shapes.Count, "Having shapes: " + str); }
public void TestReadTextBox() { XSSFWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("WithDrawing.xlsx"); XSSFSheet sheet = wb.GetSheetAt(0) as XSSFSheet; //the sheet has one relationship and it is XSSFDrawing List <RelationPart> rels = sheet.RelationParts; Assert.AreEqual(1, rels.Count); RelationPart rp = rels[0]; Assert.IsTrue(rp.DocumentPart is XSSFDrawing); XSSFDrawing drawing = (XSSFDrawing)rp.DocumentPart; //sheet.CreateDrawingPatriarch() should return the same instance of XSSFDrawing Assert.AreSame(drawing, sheet.CreateDrawingPatriarch()); String drawingId = rp.Relationship.Id; //there should be a relation to this Drawing in the worksheet Assert.IsTrue(sheet.GetCTWorksheet().IsSetDrawing()); Assert.AreEqual(drawingId, sheet.GetCTWorksheet().drawing.id); List <XSSFShape> shapes = drawing.GetShapes(); Assert.AreEqual(6, shapes.Count); Assert.IsTrue(shapes[0] is XSSFSimpleShape); XSSFSimpleShape textbox = (XSSFSimpleShape)shapes[0]; Assert.AreEqual("Sheet with various pictures\n(jpeg, png, wmf, emf and pict)", textbox.Text); checkRewrite(wb); wb.Close(); }
public void TestReadTextBox2() { XSSFWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("WithTextBox2.xlsx"); XSSFSheet sheet = wb.GetSheetAt(0) as XSSFSheet; XSSFDrawing drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing; List <XSSFShape> shapes = drawing.GetShapes(); XSSFSimpleShape textbox = (XSSFSimpleShape)shapes[0]; String extracted = textbox.Text; StringBuilder sb = new StringBuilder(); sb.Append("1. content1A\n"); sb.Append("\t1. content1B\n"); sb.Append("\t2. content2B\n"); sb.Append("\t3. content3B\n"); sb.Append("2. content2A\n"); sb.Append("\t3. content2BStartAt3\n"); sb.Append("\t\n\t\n\t"); sb.Append("4. content2BStartAt3Incremented\n"); sb.Append("\t\n\t\n\t\n\t"); Assert.AreEqual(sb.ToString(), extracted); checkRewrite(wb); wb.Close(); }
public void Test53568() { XSSFWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("53568.xlsx"); List <XSSFPictureData> pictures = wb.GetAllPictures() as List <XSSFPictureData>; Assert.IsNotNull(pictures); Assert.AreEqual(4, pictures.Count); XSSFSheet sheet1 = wb.GetSheetAt(0) as XSSFSheet; List <XSSFShape> shapes1 = (sheet1.CreateDrawingPatriarch() as XSSFDrawing).GetShapes(); Assert.IsNotNull(shapes1); Assert.AreEqual(5, shapes1.Count); for (int i = 0; i < wb.NumberOfSheets; i++) { XSSFSheet sheet = wb.GetSheetAt(i) as XSSFSheet; XSSFDrawing Drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing; foreach (XSSFShape shape in Drawing.GetShapes()) { if (shape is XSSFPicture) { XSSFPicture pic = (XSSFPicture)shape; XSSFPictureData picData = pic.PictureData as XSSFPictureData; Assert.IsNotNull(picData); } } } }
public void TestXSSFSimpleShapeCausesNPE56514() { XSSFWorkbook wb1 = XSSFTestDataSamples.OpenSampleWorkbook("56514.xlsx"); XSSFSheet sheet = wb1.GetSheetAt(0) as XSSFSheet; XSSFDrawing drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing; List <XSSFShape> shapes = drawing.GetShapes(); Assert.AreEqual(4, shapes.Count); XSSFWorkbook wb2 = XSSFTestDataSamples.WriteOutAndReadBack(wb1) as XSSFWorkbook; wb1.Close(); sheet = wb2.GetSheetAt(0) as XSSFSheet; drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing; shapes = drawing.GetShapes(); Assert.AreEqual(4, shapes.Count); wb2.Close(); }
public void Resize() { XSSFWorkbook wb = XSSFITestDataProvider.instance.OpenSampleWorkbook("resize_Compare.xlsx") as XSSFWorkbook; XSSFDrawing dp = wb.GetSheetAt(0).CreateDrawingPatriarch() as XSSFDrawing; List <XSSFShape> pics = dp.GetShapes(); XSSFPicture inpPic = (XSSFPicture)pics[(0)]; XSSFPicture cmpPic = (XSSFPicture)pics[(0)]; BaseTestResize(inpPic, cmpPic, 2.0, 2.0); wb.Close(); }
public void TestXSSFSimpleShapeCausesNPE56514() { XSSFWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("56514.xlsx"); XSSFSheet sheet = wb.GetSheetAt(0) as XSSFSheet; XSSFDrawing Drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing; List <XSSFShape> shapes = Drawing.GetShapes(); Assert.AreEqual(4, shapes.Count); wb = XSSFTestDataSamples.WriteOutAndReadBack(wb) as XSSFWorkbook; shapes = Drawing.GetShapes(); Assert.AreEqual(4, shapes.Count); /* OutputStream stream = new FileOutputStream(new File("C:\\temp\\56514.xlsx")); * try { * wb.Write(stream); * } finally { * stream.Close(); * }*/ }
public void TestRead() { XSSFWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("WithDrawing.xlsx"); XSSFSheet sheet = (XSSFSheet)wb.GetSheetAt(0); //the sheet has one relationship and it is XSSFDrawing List <RelationPart> rels = sheet.RelationParts; Assert.AreEqual(1, rels.Count); RelationPart rp = rels[0]; Assert.IsTrue(rp.DocumentPart is XSSFDrawing); XSSFDrawing drawing = (XSSFDrawing)rp.DocumentPart; //sheet.CreateDrawingPatriarch() should return the same instance of XSSFDrawing Assert.AreSame(drawing, sheet.CreateDrawingPatriarch()); String drawingId = rp.Relationship.Id; //there should be a relation to this Drawing in the worksheet Assert.IsTrue(sheet.GetCTWorksheet().IsSetDrawing()); Assert.AreEqual(drawingId, sheet.GetCTWorksheet().drawing.id); List <XSSFShape> shapes = drawing.GetShapes(); Assert.AreEqual(6, shapes.Count); Assert.IsTrue(shapes[(0)] is XSSFPicture); Assert.IsTrue(shapes[(1)] is XSSFPicture); Assert.IsTrue(shapes[(2)] is XSSFPicture); Assert.IsTrue(shapes[(3)] is XSSFPicture); Assert.IsTrue(shapes[(4)] is XSSFSimpleShape); Assert.IsTrue(shapes[(5)] is XSSFPicture); foreach (XSSFShape sh in shapes) { Assert.IsNotNull(sh.GetAnchor()); } checkRewrite(wb); wb.Close(); }
public void TestClone() { XSSFWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("WithDrawing.xlsx"); XSSFSheet sheet1 = wb.GetSheetAt(0) as XSSFSheet; XSSFSheet sheet2 = wb.CloneSheet(0) as XSSFSheet; //the source sheet has one relationship and it is XSSFDrawing List <POIXMLDocumentPart> rels1 = sheet1.GetRelations(); Assert.AreEqual(1, rels1.Count); Assert.IsTrue(rels1[(0)] is XSSFDrawing); List <POIXMLDocumentPart> rels2 = sheet2.GetRelations(); Assert.AreEqual(1, rels2.Count); Assert.IsTrue(rels2[(0)] is XSSFDrawing); XSSFDrawing drawing1 = (XSSFDrawing)rels1[0]; XSSFDrawing drawing2 = (XSSFDrawing)rels2[0]; Assert.AreNotSame(drawing1, drawing2); // Drawing2 is a clone of Drawing1 List <XSSFShape> shapes1 = drawing1.GetShapes(); List <XSSFShape> shapes2 = drawing2.GetShapes(); Assert.AreEqual(shapes1.Count, shapes2.Count); for (int i = 0; i < shapes1.Count; i++) { XSSFShape sh1 = (XSSFShape)shapes1[(i)]; XSSFShape sh2 = (XSSFShape)shapes2[i]; Assert.IsTrue(sh1.GetType() == sh2.GetType()); Assert.AreEqual(sh1.GetShapeProperties().ToString(), sh2.GetShapeProperties().ToString()); } checkRewrite(wb); wb.Close(); }
public void TestNew() { XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = (XSSFSheet)wb.CreateSheet(); //multiple calls of CreateDrawingPatriarch should return the same instance of XSSFDrawing XSSFDrawing dr1 = (XSSFDrawing)sheet.CreateDrawingPatriarch(); XSSFDrawing dr2 = (XSSFDrawing)sheet.CreateDrawingPatriarch(); Assert.AreSame(dr1, dr2); List <POIXMLDocumentPart> rels = sheet.GetRelations(); Assert.AreEqual(1, rels.Count); Assert.IsTrue(rels[0] is XSSFDrawing); XSSFDrawing drawing = (XSSFDrawing)rels[0]; String drawingId = drawing.GetPackageRelationship().Id; //there should be a relation to this Drawing in the worksheet Assert.IsTrue(sheet.GetCTWorksheet().IsSetDrawing()); Assert.AreEqual(drawingId, sheet.GetCTWorksheet().drawing.id); //XSSFClientAnchor anchor = new XSSFClientAnchor(); XSSFConnector c1 = drawing.CreateConnector(new XSSFClientAnchor(0, 0, 0, 0, 0, 0, 2, 2)); c1.LineWidth = 2.5; c1.LineStyle = SS.UserModel.LineStyle.DashDotSys; XSSFShapeGroup c2 = drawing.CreateGroup(new XSSFClientAnchor(0, 0, 0, 0, 0, 0, 5, 5)); Assert.IsNotNull(c2); XSSFSimpleShape c3 = drawing.CreateSimpleShape(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4)); c3.SetText(new XSSFRichTextString("Test String")); c3.SetFillColor(128, 128, 128); XSSFTextBox c4 = (XSSFTextBox)drawing.CreateTextbox(new XSSFClientAnchor(0, 0, 0, 0, 4, 4, 5, 6)); XSSFRichTextString rt = new XSSFRichTextString("Test String"); rt.ApplyFont(0, 5, wb.CreateFont()); rt.ApplyFont(5, 6, wb.CreateFont()); c4.SetText(rt); c4.IsNoFill = (true); Assert.AreEqual(4, drawing.GetCTDrawing().SizeOfTwoCellAnchorArray()); List <XSSFShape> shapes = drawing.GetShapes(); Assert.AreEqual(4, shapes.Count); Assert.IsTrue(shapes[(0)] is XSSFConnector); Assert.IsTrue(shapes[(1)] is XSSFShapeGroup); Assert.IsTrue(shapes[(2)] is XSSFSimpleShape); Assert.IsTrue(shapes[(3)] is XSSFSimpleShape); // Save and re-load it wb = XSSFTestDataSamples.WriteOutAndReadBack(wb) as XSSFWorkbook; sheet = wb.GetSheetAt(0) as XSSFSheet; // Check dr1 = sheet.CreateDrawingPatriarch() as XSSFDrawing; CT_Drawing ctDrawing = dr1.GetCTDrawing(); // Connector, shapes and text boxes are all two cell anchors Assert.AreEqual(0, ctDrawing.SizeOfAbsoluteAnchorArray()); Assert.AreEqual(0, ctDrawing.SizeOfOneCellAnchorArray()); Assert.AreEqual(4, ctDrawing.SizeOfTwoCellAnchorArray()); shapes = dr1.GetShapes(); Assert.AreEqual(4, shapes.Count); Assert.IsTrue(shapes[0] is XSSFConnector); Assert.IsTrue(shapes[1] is XSSFShapeGroup); Assert.IsTrue(shapes[2] is XSSFSimpleShape); Assert.IsTrue(shapes[3] is XSSFSimpleShape); // // Ensure it got the right namespaces //String xml = ctDrawing.ToString(); //Assert.IsTrue(xml.Contains("xmlns:xdr=\"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing\"")); //Assert.IsTrue(xml.Contains("xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\"")); Assert.IsNotNull(XSSFTestDataSamples.WriteOutAndReadBack(wb)); }
public void TestAddBulletParagraphs() { XSSFWorkbook wb1 = new XSSFWorkbook(); XSSFSheet sheet = wb1.CreateSheet() as XSSFSheet; XSSFDrawing drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing; XSSFTextBox shape = drawing.CreateTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 10, 20)); String paraString1 = "A normal paragraph"; String paraString2 = "First bullet"; String paraString3 = "Second bullet (level 1)"; String paraString4 = "Third bullet"; String paraString5 = "Another normal paragraph"; String paraString6 = "First numbered bullet"; String paraString7 = "Second bullet (level 1)"; String paraString8 = "Third bullet (level 1)"; String paraString9 = "Fourth bullet (level 1)"; String paraString10 = "Fifth Bullet"; XSSFTextParagraph para = shape.AddNewTextParagraph(paraString1); para = shape.AddNewTextParagraph(paraString2); para.SetBullet(true); para = shape.AddNewTextParagraph(paraString3); para.SetBullet(true); para.Level = (1); para = shape.AddNewTextParagraph(paraString4); para.SetBullet(true); para = shape.AddNewTextParagraph(paraString5); para = shape.AddNewTextParagraph(paraString6); para.SetBullet(ListAutoNumber.ARABIC_PERIOD); para = shape.AddNewTextParagraph(paraString7); para.SetBullet(ListAutoNumber.ARABIC_PERIOD, 3); para.Level = (1); para = shape.AddNewTextParagraph(paraString8); para.SetBullet(ListAutoNumber.ARABIC_PERIOD, 3); para.Level = (1); para = shape.AddNewTextParagraph(""); para.SetBullet(ListAutoNumber.ARABIC_PERIOD, 3); para.Level = (1); para = shape.AddNewTextParagraph(paraString9); para.SetBullet(ListAutoNumber.ARABIC_PERIOD, 3); para.Level = (1); para = shape.AddNewTextParagraph(paraString10); para.SetBullet(ListAutoNumber.ARABIC_PERIOD); // Save and re-load it XSSFWorkbook wb2 = XSSFTestDataSamples.WriteOutAndReadBack(wb1); sheet = wb2.GetSheetAt(0) as XSSFSheet; // Check drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing; List <XSSFShape> shapes = drawing.GetShapes(); Assert.AreEqual(1, shapes.Count); Assert.IsTrue(shapes[0] is XSSFSimpleShape); XSSFSimpleShape sshape = (XSSFSimpleShape)shapes[0]; List <XSSFTextParagraph> paras = sshape.TextParagraphs; Assert.AreEqual(12, paras.Count); // this should be 12 as XSSFSimpleShape Creates a default paragraph (no text), and then we Added to that StringBuilder builder = new StringBuilder(); builder.Append(paraString1); builder.Append("\n"); builder.Append("\u2022 "); builder.Append(paraString2); builder.Append("\n"); builder.Append("\t\u2022 "); builder.Append(paraString3); builder.Append("\n"); builder.Append("\u2022 "); builder.Append(paraString4); builder.Append("\n"); builder.Append(paraString5); builder.Append("\n"); builder.Append("1. "); builder.Append(paraString6); builder.Append("\n"); builder.Append("\t3. "); builder.Append(paraString7); builder.Append("\n"); builder.Append("\t4. "); builder.Append(paraString8); builder.Append("\n"); builder.Append("\t"); // should be empty builder.Append("\n"); builder.Append("\t5. "); builder.Append(paraString9); builder.Append("\n"); builder.Append("2. "); builder.Append(paraString10); Assert.AreEqual(builder.ToString(), sshape.Text); checkRewrite(wb2); wb2.Close(); }
public void TestReadTextBoxParagraphs() { XSSFWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("WithTextBox.xlsx"); XSSFSheet sheet = wb.GetSheetAt(0) as XSSFSheet; //the sheet has one relationship and it is XSSFDrawing List <RelationPart> rels = sheet.RelationParts; Assert.AreEqual(1, rels.Count); RelationPart rp = rels[0]; Assert.IsTrue(rp.DocumentPart is XSSFDrawing); XSSFDrawing drawing = (XSSFDrawing)rp.DocumentPart; //sheet.CreateDrawingPatriarch() should return the same instance of XSSFDrawing Assert.AreSame(drawing, sheet.CreateDrawingPatriarch()); String drawingId = rp.Relationship.Id; //there should be a relation to this Drawing in the worksheet Assert.IsTrue(sheet.GetCTWorksheet().IsSetDrawing()); Assert.AreEqual(drawingId, sheet.GetCTWorksheet().drawing.id); List <XSSFShape> shapes = drawing.GetShapes(); Assert.AreEqual(1, shapes.Count); Assert.IsTrue(shapes[0] is XSSFSimpleShape); XSSFSimpleShape textbox = (XSSFSimpleShape)shapes[0]; List <XSSFTextParagraph> paras = textbox.TextParagraphs; Assert.AreEqual(3, paras.Count); Assert.AreEqual("Line 2", paras[1].Text); // check content of second paragraph Assert.AreEqual("Line 1\nLine 2\nLine 3", textbox.Text); // check content of entire textbox // check attributes of paragraphs Assert.AreEqual(TextAlign.LEFT, paras[0].TextAlign); Assert.AreEqual(TextAlign.CENTER, paras[1].TextAlign); Assert.AreEqual(TextAlign.RIGHT, paras[2].TextAlign); Color clr = paras[0].TextRuns[0].FontColor; Assert.IsTrue(Arrays.Equals( new int[] { 255, 0, 0 }, new int[] { clr.R, clr.G, clr.B })); clr = paras[1].TextRuns[0].FontColor; Assert.IsTrue(Arrays.Equals( new int[] { 0, 255, 0 }, new int[] { clr.R, clr.G, clr.B })); clr = paras[2].TextRuns[0].FontColor; Assert.IsTrue(Arrays.Equals( new int[] { 0, 0, 255 }, new int[] { clr.R, clr.G, clr.B })); checkRewrite(wb); wb.Close(); }
public void TestAddNewTextParagraphWithRTS() { XSSFWorkbook wb1 = new XSSFWorkbook(); XSSFSheet sheet = wb1.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 Rich Text String"); XSSFFont font = wb1.CreateFont() as XSSFFont; font.SetColor(new XSSFColor(Color.FromArgb(0, 255, 255))); font.FontName = ("Arial"); rt.ApplyFont(font); XSSFFont midfont = wb1.CreateFont() as XSSFFont; midfont.SetColor(new XSSFColor(Color.FromArgb(0, 255, 0))); rt.ApplyFont(5, 14, midfont); // Set the text "Rich Text" to be green and the default font XSSFTextParagraph para = shape.AddNewTextParagraph(rt); // Save and re-load it XSSFWorkbook wb2 = XSSFTestDataSamples.WriteOutAndReadBack(wb1) as XSSFWorkbook; wb1.Close(); sheet = wb2.GetSheetAt(0) as XSSFSheet; // Check Drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing; List <XSSFShape> shapes = Drawing.GetShapes(); Assert.AreEqual(1, shapes.Count); Assert.IsTrue(shapes[0] is XSSFSimpleShape); XSSFSimpleShape sshape = (XSSFSimpleShape)shapes[0]; List <XSSFTextParagraph> paras = sshape.TextParagraphs; Assert.AreEqual(2, paras.Count); // this should be 2 as XSSFSimpleShape Creates a default paragraph (no text), and then we add a string to that. List <XSSFTextRun> runs = para.TextRuns; Assert.AreEqual(3, runs.Count); // first run properties Assert.AreEqual("Test ", runs[0].Text); Assert.AreEqual("Arial", runs[0].FontFamily); Color clr = runs[0].FontColor; Assert.IsTrue(Arrays.Equals( new int[] { 0, 255, 255 }, new int[] { clr.R, clr.G, clr.B })); // second run properties Assert.AreEqual("Rich Text", runs[1].Text); Assert.AreEqual(XSSFFont.DEFAULT_FONT_NAME, runs[1].FontFamily); clr = runs[1].FontColor; Assert.IsTrue(Arrays.Equals( new int[] { 0, 255, 0 }, new int[] { clr.R, clr.G, clr.B })); // third run properties Assert.AreEqual(" String", runs[2].Text); Assert.AreEqual("Arial", runs[2].FontFamily); clr = runs[2].FontColor; Assert.IsTrue(Arrays.Equals( new int[] { 0, 255, 255 }, new int[] { clr.R, clr.G, clr.B })); checkRewrite(wb2); wb2.Close(); }