/** * Creates the low level OBJ record for this shape. */ private ObjRecord CreateObjRecord(HSSFSimpleShape shape, int shapeId) { ObjRecord obj = new ObjRecord(); CommonObjectDataSubRecord c = new CommonObjectDataSubRecord(); c.ObjectType = CommonObjectType.COMBO_BOX; c.ObjectId = shapeId; c.IsLocked = true; c.IsPrintable = false; c.IsAutoFill = true; c.IsAutoline = false; FtCblsSubRecord f = new FtCblsSubRecord(); LbsDataSubRecord l = LbsDataSubRecord.CreateAutoFilterInstance(); EndSubRecord e = new EndSubRecord(); obj.AddSubRecord(c); obj.AddSubRecord(f); obj.AddSubRecord(l); obj.AddSubRecord(e); return(obj); }
public void TestHSSFShapeCompatibility() { HSSFSimpleShape shape = new HSSFSimpleShape(null, new HSSFClientAnchor()); shape.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_LINE); Assert.AreEqual(0x08000040, shape.LineStyleColor); Assert.AreEqual(0x08000009, shape.FillColor); Assert.AreEqual(HSSFShape.LINEWIDTH_DEFAULT, shape.LineWidth); Assert.AreEqual(HSSFShape.LINESTYLE_SOLID, shape.LineStyle); Assert.IsFalse(shape.IsNoFill); AbstractShape sp = AbstractShape.CreateShape(shape, 1); EscherContainerRecord spContainer = sp.SpContainer; EscherOptRecord opt = spContainer.GetChildById(EscherOptRecord.RECORD_ID) as EscherOptRecord; Assert.AreEqual(7, opt.EscherProperties.Count); Assert.AreEqual(true, ((EscherBoolProperty)opt.Lookup(EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE)).IsTrue); Assert.AreEqual(0x00000004, ((EscherSimpleProperty)opt.Lookup(EscherProperties.GEOMETRY__SHAPEPATH)).PropertyValue); Assert.AreEqual(0x08000009, ((EscherSimpleProperty)opt.Lookup(EscherProperties.FILL__FILLCOLOR)).PropertyValue); Assert.AreEqual(true, ((EscherBoolProperty)opt.Lookup(EscherProperties.FILL__NOFILLHITTEST)).IsTrue); Assert.AreEqual(0x08000040, ((EscherSimpleProperty)opt.Lookup(EscherProperties.LINESTYLE__COLOR)).PropertyValue); Assert.AreEqual(true, ((EscherBoolProperty)opt.Lookup(EscherProperties.LINESTYLE__NOLINEDRAWDASH)).IsTrue); Assert.AreEqual(true, ((EscherBoolProperty)opt.Lookup(EscherProperties.GROUPSHAPE__PRINT)).IsTrue); }
private static void DrawSheet3(ISheet sheet3) { // Create a row and size one of the cells reasonably large IRow row = sheet3.CreateRow(2); row.HeightInPoints = 140; row.CreateCell(1); sheet3.SetColumnWidth(2, 9000); // Create the Drawing patriarch. This is the top level container for // all shapes. This will clear out any existing shapes for that sheet. HSSFPatriarch patriarch = (HSSFPatriarch)sheet3.CreateDrawingPatriarch(); // Create a shape group. HSSFShapeGroup group = patriarch.CreateGroup( new HSSFClientAnchor(0, 0, 900, 200, (short)2, 2, (short)2, 2)); // Create a couple of lines in the group. HSSFSimpleShape shape1 = group.CreateShape(new HSSFChildAnchor(3, 3, 500, 500)); shape1.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_LINE); ((HSSFChildAnchor)shape1.Anchor).SetAnchor((short)3, 3, 500, 500); HSSFSimpleShape shape2 = group.CreateShape(new HSSFChildAnchor((short)1, 200, 400, 600)); shape2.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_LINE); }
public void TestRotation() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sheet.CreateDrawingPatriarch() as HSSFPatriarch; HSSFSimpleShape rectangle = patriarch.CreateSimpleShape(new HSSFClientAnchor(0, 0, 100, 100, (short)0, 0, (short)5, 5)); rectangle.ShapeType = HSSFSimpleShape.OBJECT_TYPE_RECTANGLE; Assert.AreEqual(rectangle.RotationDegree, 0); rectangle.RotationDegree = (short)45; Assert.AreEqual(rectangle.RotationDegree, 45); rectangle.IsFlipHorizontal = true; wb = HSSFTestDataSamples.WriteOutAndReadBack(wb); sheet = wb.GetSheetAt(0) as HSSFSheet; patriarch = sheet.DrawingPatriarch as HSSFPatriarch; rectangle = (HSSFSimpleShape)patriarch.Children[0]; Assert.AreEqual(rectangle.RotationDegree, 45); rectangle.RotationDegree = (short)30; Assert.AreEqual(rectangle.RotationDegree, 30); patriarch.SetCoordinates(0, 0, 10, 10); rectangle.String = new HSSFRichTextString("1234"); }
/** * Generates the escher shape records for this shape. */ private EscherContainerRecord CreateSpContainer(HSSFSimpleShape shape, int shapeId) { EscherContainerRecord spContainer = new EscherContainerRecord(); EscherSpRecord sp = new EscherSpRecord(); EscherOptRecord opt = new EscherOptRecord(); EscherClientDataRecord clientData = new EscherClientDataRecord(); spContainer.RecordId = (EscherContainerRecord.SP_CONTAINER); spContainer.Options = ((short)0x000F); sp.RecordId = (EscherSpRecord.RECORD_ID); sp.Options = ((short)((EscherAggregate.ST_HOSTCONTROL << 4) | 0x2)); sp.ShapeId = (shapeId); sp.Flags = (EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE); opt.RecordId = (EscherOptRecord.RECORD_ID); opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 17039620)); opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x00080008)); opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080000)); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.GROUPSHAPE__PRINT, 0x00020000)); HSSFClientAnchor userAnchor = (HSSFClientAnchor)shape.Anchor; userAnchor.AnchorType = 1; EscherRecord anchor = CreateAnchor(userAnchor); clientData.RecordId = (EscherClientDataRecord.RECORD_ID); clientData.Options = ((short)0x0000); spContainer.AddChildRecord(sp); spContainer.AddChildRecord(opt); spContainer.AddChildRecord(anchor); spContainer.AddChildRecord(clientData); return(spContainer); }
private static void DrawLinesToCenter(HSSFPatriarch patriarch) { // Draw some lines from and to the corners { HSSFClientAnchor a1 = new HSSFClientAnchor(); a1.SetAnchor((short)2, 2, 0, 0, (short)2, 2, 512, 128); HSSFSimpleShape shape1 = patriarch.CreateSimpleShape(a1); shape1.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_LINE); } { HSSFClientAnchor a1 = new HSSFClientAnchor(); a1.SetAnchor((short)2, 2, 512, 128, (short)2, 2, 1023, 0); HSSFSimpleShape shape1 = patriarch.CreateSimpleShape(a1); shape1.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_LINE); } { HSSFClientAnchor a1 = new HSSFClientAnchor(); a1.SetAnchor((short)1, 1, 0, 0, (short)1, 1, 512, 100); HSSFSimpleShape shape1 = patriarch.CreateSimpleShape(a1); shape1.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_LINE); } { HSSFClientAnchor a1 = new HSSFClientAnchor(); a1.SetAnchor((short)1, 1, 512, 100, (short)1, 1, 1023, 0); HSSFSimpleShape shape1 = patriarch.CreateSimpleShape(a1); shape1.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_LINE); } }
/// <summary> /// Creates the lowerlevel escher records for this shape. /// </summary> /// <param name="hssfShape">The HSSF shape.</param> /// <param name="shapeId">The shape id.</param> /// <returns></returns> private EscherContainerRecord CreateSpContainer(HSSFSimpleShape hssfShape, int shapeId) { HSSFShape shape = hssfShape; EscherContainerRecord spContainer = new EscherContainerRecord(); EscherSpRecord sp = new EscherSpRecord(); EscherOptRecord opt = new EscherOptRecord(); EscherClientDataRecord clientData = new EscherClientDataRecord(); spContainer.RecordId = EscherContainerRecord.SP_CONTAINER; spContainer.Options = (short)0x000F; sp.RecordId = EscherSpRecord.RECORD_ID; short shapeType = objTypeToShapeType(hssfShape.ShapeType); sp.Options = (short)((shapeType << 4) | 0x2); sp.ShapeId = shapeId; sp.Flags = EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE; opt.RecordId = EscherOptRecord.RECORD_ID; AddStandardOptions(shape, opt); EscherRecord anchor = CreateAnchor(shape.Anchor); clientData.RecordId = EscherClientDataRecord.RECORD_ID; clientData.Options = (short)0x0000; spContainer.AddChildRecord(sp); spContainer.AddChildRecord(opt); spContainer.AddChildRecord(anchor); spContainer.AddChildRecord(clientData); return(spContainer); }
public void TestAutoFilter() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sh = (HSSFSheet)wb.CreateSheet(); InternalWorkbook iwb = wb.Workbook; InternalSheet ish = sh.Sheet; Assert.IsNull(iwb.GetSpecificBuiltinRecord(NameRecord.BUILTIN_FILTER_DB, 1)); Assert.IsNull(ish.FindFirstRecordBySid(AutoFilterInfoRecord.sid)); CellRangeAddress range = CellRangeAddress.ValueOf("A1:B10"); sh.SetAutoFilter(range); NameRecord name = iwb.GetSpecificBuiltinRecord(NameRecord.BUILTIN_FILTER_DB, 1); Assert.IsNotNull(name); // The built-in name for auto-filter must consist of a single Area3d Ptg. Ptg[] ptg = name.NameDefinition; Assert.AreEqual(1, ptg.Length, "The built-in name for auto-filter must consist of a single Area3d Ptg"); Assert.IsTrue(ptg[0] is Area3DPtg, "The built-in name for auto-filter must consist of a single Area3d Ptg"); Area3DPtg aref = (Area3DPtg)ptg[0]; Assert.AreEqual(range.FirstColumn, aref.FirstColumn); Assert.AreEqual(range.FirstRow, aref.FirstRow); Assert.AreEqual(range.LastColumn, aref.LastColumn); Assert.AreEqual(range.LastRow, aref.LastRow); // verify AutoFilterInfoRecord AutoFilterInfoRecord afilter = (AutoFilterInfoRecord)ish.FindFirstRecordBySid(AutoFilterInfoRecord.sid); Assert.IsNotNull(afilter); Assert.AreEqual(2, afilter.NumEntries); //filter covers two columns HSSFPatriarch dr = (HSSFPatriarch)sh.DrawingPatriarch; Assert.IsNotNull(dr); HSSFSimpleShape comboBoxShape = (HSSFSimpleShape)dr.Children[0]; Assert.AreEqual(comboBoxShape.ShapeType, HSSFSimpleShape.OBJECT_TYPE_COMBO_BOX); Assert.IsNull(ish.FindFirstRecordBySid(ObjRecord.sid)); // ObjRecord will appear after serializetion wb = HSSFTestDataSamples.WriteOutAndReadBack(wb); sh = (HSSFSheet)wb.GetSheetAt(0); ish = sh.Sheet; ObjRecord objRecord = (ObjRecord)ish.FindFirstRecordBySid(ObjRecord.sid); IList subRecords = objRecord.SubRecords; Assert.AreEqual(3, subRecords.Count); Assert.IsTrue(subRecords[0] is CommonObjectDataSubRecord); Assert.IsTrue(subRecords[1] is FtCblsSubRecord); // must be present, see Bug 51481 Assert.IsTrue(subRecords[2] is LbsDataSubRecord); }
/// <summary> /// Hàm vẽ một line trên file excel /// </summary> /// <param name="sheet"></param> /// <param name="col1">Cột chứa điểm đầu của line</param> /// <param name="row1">Dòng chứa điểm đầu của line</param> /// <param name="x1">Tọa độ X điểm đầu của line (Tọa độ x trong 1 cell có giá trị từ 0 - 1023)</param> /// <param name="y1">Tọa độ Y điểm đầu của line (Tọa độ Y trong 1 cell có giá trị từ 0 - 255)</param> /// <param name="col2">Cột chứa điểm cuối của line</param> /// <param name="row2">Dòng chứa điểm cuối của line</param> /// <param name="x2">Tọa độ X điểm cuối của line</param> /// <param name="y2">Tọa độ Y điểm cuối của line</param> /// <modified> /// Author Date comment /// TuanVM 15/07/2012 Tạo mới /// </modified> public static void DrawLine(this ISheet sheet, short col1, int row1, int x1, int y1, short col2, int row2, int x2, int y2) { HSSFPatriarch patriarch = (HSSFPatriarch)sheet.CreateDrawingPatriarch(); HSSFClientAnchor a1 = new HSSFClientAnchor(); a1.SetAnchor(col1, row1, x1, y1, col2, row2, x2, y2); HSSFSimpleShape shape1 = patriarch.CreateSimpleShape(a1); shape1.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_LINE); }
public void TestFillRect() { graphics.FillRect(10, 10, 20, 20); HSSFSimpleShape s = (HSSFSimpleShape)escherGroupA.Children[0]; Assert.AreEqual(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE, s.ShapeType); Assert.AreEqual(10, s.Anchor.Dx1); Assert.AreEqual(10, s.Anchor.Dy1); Assert.AreEqual(30, s.Anchor.Dy2); Assert.AreEqual(30, s.Anchor.Dx2); }
public void TestFillRect() { graphics.fillRect(10, 10, 20, 20); HSSFSimpleShape s = (HSSFSimpleShape)escherGroup.GetChildren()[0]; Assert.AreEqual(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE, s.GetShapeType()); Assert.AreEqual(10, s.GetAnchor().GetDx1()); Assert.AreEqual(10, s.GetAnchor().GetDy1()); Assert.AreEqual(30, s.GetAnchor().GetDy2()); Assert.AreEqual(30, s.GetAnchor().GetDx2()); }
/// <summary> /// Create a new shape object used to Create the escher records. /// </summary> /// <param name="hssfShape">The simple shape this Is based on.</param> /// <param name="shapeId">The shape id.</param> /// <returns></returns> public static AbstractShape CreateShape(HSSFShape hssfShape, int shapeId) { AbstractShape shape; if (hssfShape is HSSFComment) { shape = new CommentShape((HSSFComment)hssfShape, shapeId); } else if (hssfShape is HSSFTextbox) { shape = new TextboxShape((HSSFTextbox)hssfShape, shapeId); } else if (hssfShape is HSSFPolygon) { shape = new PolygonShape((HSSFPolygon)hssfShape, shapeId); } else if (hssfShape is HSSFSimpleShape) { HSSFSimpleShape simpleShape = (HSSFSimpleShape)hssfShape; switch (simpleShape.ShapeType) { case HSSFSimpleShape.OBJECT_TYPE_PICTURE: shape = new PictureShape(simpleShape, shapeId); break; case HSSFSimpleShape.OBJECT_TYPE_LINE: shape = new LineShape(simpleShape, shapeId); break; case HSSFSimpleShape.OBJECT_TYPE_OVAL: case HSSFSimpleShape.OBJECT_TYPE_RECTANGLE: shape = new SimpleFilledShape(simpleShape, shapeId); break; case HSSFSimpleShape.OBJECT_TYPE_COMBO_BOX: shape = new ComboboxShape(simpleShape, shapeId); break; default: throw new ArgumentException("Do not know how to handle this type of shape"); } } else { throw new ArgumentException("Unknown shape type"); } EscherSpRecord sp = (EscherSpRecord)shape.SpContainer.GetChildById(EscherSpRecord.RECORD_ID); if (hssfShape.Parent != null) { sp.Flags = sp.Flags | EscherSpRecord.FLAG_CHILD; } return(shape); }
public void TestBug45312() { HSSFWorkbook wb = new HSSFWorkbook(); try { HSSFSheet sheet = wb.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sheet.CreateDrawingPatriarch() as HSSFPatriarch; { HSSFClientAnchor a1 = new HSSFClientAnchor(); a1.SetAnchor((short)1, 1, 0, 0, (short)1, 1, 512, 100); HSSFSimpleShape shape1 = patriarch.CreateSimpleShape(a1); shape1.ShapeType = (/*setter*/ HSSFSimpleShape.OBJECT_TYPE_LINE); } { HSSFClientAnchor a1 = new HSSFClientAnchor(); //setAnchor method is wrong?? a1.SetAnchor((short)1, 1, 512, 0, (short)1, 1, 1023, 100); HSSFSimpleShape shape1 = patriarch.CreateSimpleShape(a1); shape1.FlipVertical = (true); shape1.ShapeType = (/*setter*/ HSSFSimpleShape.OBJECT_TYPE_LINE); } { HSSFClientAnchor a1 = new HSSFClientAnchor(); a1.SetAnchor((short)2, 2, 0, 0, (short)2, 2, 512, 100); HSSFSimpleShape shape1 = patriarch.CreateSimpleShape(a1); shape1.ShapeType = (/*setter*/ HSSFSimpleShape.OBJECT_TYPE_LINE); } { HSSFClientAnchor a1 = new HSSFClientAnchor(); a1.SetAnchor((short)2, 2, 0, 100, (short)2, 2, 512, 200); HSSFSimpleShape shape1 = patriarch.CreateSimpleShape(a1); shape1.FlipHorizontal = (/*setter*/ true); shape1.ShapeType = (/*setter*/ HSSFSimpleShape.OBJECT_TYPE_LINE); } /*OutputStream stream = new FileOutputStream("/tmp/45312.xls"); * try { * wb.Write(stream); * } finally { * stream.Close(); * }*/ CheckWorkbookBack(wb); } finally { //wb.Close(); } }
public void TestDraw() { graphics.draw(new Line2D.Double(10, 10, 20, 20)); HSSFSimpleShape s = (HSSFSimpleShape)escherGroup.GetChildren()[0]; Assert.IsTrue(s.GetShapeType() == HSSFSimpleShape.OBJECT_TYPE_LINE); Assert.AreEqual(10, s.GetAnchor().GetDx1()); Assert.AreEqual(10, s.GetAnchor().GetDy1()); Assert.AreEqual(20, s.GetAnchor().GetDx2()); Assert.AreEqual(20, s.GetAnchor().GetDy2()); System.Console.WriteLine("s = " + s); }
private static void DrawOval(HSSFPatriarch patriarch) { // Create an oval and style to taste. HSSFClientAnchor a = new HSSFClientAnchor(); a.SetAnchor((short)2, 2, 20, 20, (short)2, 2, 190, 80); HSSFSimpleShape s = patriarch.CreateSimpleShape(a); s.ShapeType = HSSFSimpleShape.OBJECT_TYPE_OVAL; s.SetLineStyleColor(10, 10, 10); s.SetFillColor(90, 10, 200); s.LineWidth = HSSFShape.LINEWIDTH_ONE_PT * 3; s.LineStyle = LineStyle.DotSys; }
public void TestTextForSimpleShape() { HSSFWorkbook wb1 = new HSSFWorkbook(); HSSFSheet sheet = wb1.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sheet.CreateDrawingPatriarch() as HSSFPatriarch; HSSFSimpleShape shape = patriarch.CreateSimpleShape(new HSSFClientAnchor()); shape.ShapeType = HSSFSimpleShape.OBJECT_TYPE_RECTANGLE; EscherAggregate agg = HSSFTestHelper.GetEscherAggregate(patriarch); Assert.AreEqual(agg.GetShapeToObjMapping().Count, 2); HSSFWorkbook wb2 = HSSFTestDataSamples.WriteOutAndReadBack(wb1); wb1.Close(); sheet = wb2.GetSheetAt(0) as HSSFSheet; patriarch = sheet.DrawingPatriarch as HSSFPatriarch; shape = (HSSFSimpleShape)patriarch.Children[0]; agg = HSSFTestHelper.GetEscherAggregate(patriarch); Assert.AreEqual(agg.GetShapeToObjMapping().Count, 2); shape.String = new HSSFRichTextString("string1"); Assert.AreEqual(shape.String.String, "string1"); Assert.IsNotNull(HSSFTestHelper.GetEscherContainer(shape).GetChildById(EscherTextboxRecord.RECORD_ID)); Assert.AreEqual(agg.GetShapeToObjMapping().Count, 2); HSSFWorkbook wb3 = HSSFTestDataSamples.WriteOutAndReadBack(wb2); wb2.Close(); HSSFWorkbook wb4 = HSSFTestDataSamples.WriteOutAndReadBack(wb3); wb3.Close(); sheet = wb4.GetSheetAt(0) as HSSFSheet; patriarch = sheet.DrawingPatriarch as HSSFPatriarch; shape = (HSSFSimpleShape)patriarch.Children[0]; Assert.IsNotNull(HSSFTestHelper.GetTextObjRecord(shape)); Assert.AreEqual(shape.String.String, "string1"); Assert.IsNotNull(HSSFTestHelper.GetEscherContainer(shape).GetChildById(EscherTextboxRecord.RECORD_ID)); Assert.AreEqual(agg.GetShapeToObjMapping().Count, 2); wb4.Close(); }
public void TestShapeFlip() { HSSFWorkbook wb1 = new HSSFWorkbook(); HSSFSheet sheet = wb1.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sheet.CreateDrawingPatriarch() as HSSFPatriarch; HSSFSimpleShape rectangle = patriarch.CreateSimpleShape(new HSSFClientAnchor()); rectangle.ShapeType = HSSFSimpleShape.OBJECT_TYPE_RECTANGLE; Assert.AreEqual(rectangle.IsFlipVertical, false); Assert.AreEqual(rectangle.IsFlipHorizontal, false); rectangle.IsFlipVertical = true; Assert.AreEqual(rectangle.IsFlipVertical, true); rectangle.IsFlipHorizontal = true; Assert.AreEqual(rectangle.IsFlipHorizontal, true); HSSFWorkbook wb2 = HSSFTestDataSamples.WriteOutAndReadBack(wb1); wb1.Close(); sheet = wb2.GetSheetAt(0) as HSSFSheet; patriarch = sheet.DrawingPatriarch as HSSFPatriarch; rectangle = (HSSFSimpleShape)patriarch.Children[0]; Assert.AreEqual(rectangle.IsFlipHorizontal, true); rectangle.IsFlipHorizontal = false; Assert.AreEqual(rectangle.IsFlipHorizontal, false); Assert.AreEqual(rectangle.IsFlipVertical, true); rectangle.IsFlipVertical = false; Assert.AreEqual(rectangle.IsFlipVertical, false); HSSFWorkbook wb3 = HSSFTestDataSamples.WriteOutAndReadBack(wb2); wb2.Close(); sheet = wb3.GetSheetAt(0) as HSSFSheet; patriarch = sheet.DrawingPatriarch as HSSFPatriarch; rectangle = (HSSFSimpleShape)patriarch.Children[0]; Assert.AreEqual(rectangle.IsFlipVertical, false); Assert.AreEqual(rectangle.IsFlipHorizontal, false); wb3.Close(); }
public void TestInitState() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sh = wb.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch; EscherAggregate agg = HSSFTestHelper.GetEscherAggregate(patriarch); Assert.AreEqual(agg.TailRecords.Count, 0); HSSFComment comment = patriarch.CreateCellComment(new HSSFClientAnchor()) as HSSFComment; Assert.AreEqual(agg.TailRecords.Count, 1); HSSFSimpleShape shape = patriarch.CreateSimpleShape(new HSSFClientAnchor()); Assert.AreEqual(comment.GetOptRecord().EscherProperties.Count, 10); }
public void TestReadExistingRectangle() { HSSFWorkbook wb = HSSFTestDataSamples.OpenSampleWorkbook("drawings.xls"); HSSFSheet sheet = wb.GetSheet("rectangles") as HSSFSheet; HSSFPatriarch Drawing = sheet.DrawingPatriarch as HSSFPatriarch; Assert.AreEqual(1, Drawing.Children.Count); HSSFSimpleShape shape = (HSSFSimpleShape)Drawing.Children[0]; Assert.AreEqual(shape.IsNoFill, false); Assert.AreEqual((int)shape.LineStyle, HSSFShape.LINESTYLE_DASHDOTGEL); Assert.AreEqual(shape.LineStyleColor, 0x616161); Assert.AreEqual(shape.FillColor, 0x2CE03D, HexDump.ToHex(shape.FillColor)); Assert.AreEqual(shape.LineWidth, HSSFShape.LINEWIDTH_ONE_PT * 2); Assert.AreEqual(shape.String.String, "POItest"); Assert.AreEqual(shape.RotationDegree, 27); }
/// <summary> /// Creates the lowerlevel escher records for this shape. /// </summary> /// <param name="hssfShape">The HSSF shape.</param> /// <param name="shapeId">The shape id.</param> /// <returns></returns> private EscherContainerRecord CreateSpContainer(HSSFSimpleShape hssfShape, int shapeId) { HSSFPicture shape = (HSSFPicture)hssfShape; EscherContainerRecord spContainer = new EscherContainerRecord(); EscherSpRecord sp = new EscherSpRecord(); EscherOptRecord opt = new EscherOptRecord(); EscherRecord anchor; EscherClientDataRecord clientData = new EscherClientDataRecord(); spContainer.RecordId = EscherContainerRecord.SP_CONTAINER; spContainer.Options = (short)0x000F; sp.RecordId = EscherSpRecord.RECORD_ID; sp.Options = (short)((EscherAggregate.ST_PICTUREFRAME << 4) | 0x2); sp.ShapeId = shapeId; sp.Flags = EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE; opt.RecordId = EscherOptRecord.RECORD_ID; // opt.AddEscherProperty( new EscherBoolProperty( EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x00800080 ) ; opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.BLIP__BLIPTODISPLAY, false, true, shape.PictureIndex)); // opt.AddEscherProperty( new EscherComplexProperty( EscherProperties.BLIP__BLIPFILENAME, true, new byte[] { (byte)0x74, (byte)0x00, (byte)0x65, (byte)0x00, (byte)0x73, (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x00, (byte)0x00 } ) ; // opt.AddEscherProperty( new EscherSimpleProperty( EscherProperties.Fill__FillTYPE, 0x00000003 ) ; AddStandardOptions(shape, opt); HSSFAnchor userAnchor = shape.Anchor; if (userAnchor.IsHorizontallyFlipped) { sp.Flags = sp.Flags | EscherSpRecord.FLAG_FLIPHORIZ; } if (userAnchor.IsVerticallyFlipped) { sp.Flags = sp.Flags | EscherSpRecord.FLAG_FLIPVERT; } anchor = CreateAnchor(userAnchor); clientData.RecordId = EscherClientDataRecord.RECORD_ID; clientData.Options = (short)0x0000; spContainer.AddChildRecord(sp); spContainer.AddChildRecord(opt); spContainer.AddChildRecord(anchor); spContainer.AddChildRecord(clientData); return(spContainer); }
public void TestHSSFShapeCompatibility() { HSSFSimpleShape shape = new HSSFSimpleShape(null, new HSSFClientAnchor()); shape.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_LINE); Assert.AreEqual(0x08000040, shape.LineStyleColor); Assert.AreEqual(0x08000009, shape.FillColor); Assert.AreEqual(HSSFShape.LINEWIDTH_DEFAULT, shape.LineWidth); Assert.AreEqual(HSSFShape.LINESTYLE_SOLID, shape.LineStyle); Assert.IsFalse(shape.IsNoFill); EscherOptRecord opt = shape.GetOptRecord(); Assert.AreEqual(7, opt.EscherProperties.Count); Assert.IsTrue(((EscherBoolProperty)opt.Lookup(EscherProperties.GROUPSHAPE__PRINT)).IsTrue); Assert.IsTrue(((EscherBoolProperty)opt.Lookup(EscherProperties.LINESTYLE__NOLINEDRAWDASH)).IsTrue); Assert.AreEqual(0x00000004, ((EscherSimpleProperty)opt.Lookup(EscherProperties.GEOMETRY__SHAPEPATH)).PropertyValue); Assert.IsNull(opt.Lookup(EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE)); }
/// <summary> /// Creates the lowerlevel escher records for this shape. /// </summary> /// <param name="hssfShape">The HSSF shape.</param> /// <param name="shapeId">The shape id.</param> /// <returns></returns> private EscherContainerRecord CreateSpContainer(HSSFSimpleShape hssfShape, int shapeId) { HSSFShape shape = hssfShape; EscherContainerRecord spContainer = new EscherContainerRecord(); EscherSpRecord sp = new EscherSpRecord(); EscherOptRecord opt = new EscherOptRecord(); EscherRecord anchor = new EscherClientAnchorRecord(); EscherClientDataRecord clientData = new EscherClientDataRecord(); spContainer.RecordId = EscherContainerRecord.SP_CONTAINER; spContainer.Options = (short)0x000F; sp.RecordId = EscherSpRecord.RECORD_ID; sp.Options = (short)((EscherAggregate.ST_LINE << 4) | 0x2); sp.ShapeId = shapeId; sp.Flags = EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE; opt.RecordId = EscherOptRecord.RECORD_ID; opt.AddEscherProperty(new EscherShapePathProperty(EscherProperties.GEOMETRY__SHAPEPATH, EscherShapePathProperty.COMPLEX)); opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 1048592)); AddStandardOptions(shape, opt); HSSFAnchor userAnchor = shape.Anchor; if (userAnchor.IsHorizontallyFlipped) { sp.Flags = sp.Flags | EscherSpRecord.FLAG_FLIPHORIZ; } if (userAnchor.IsVerticallyFlipped) { sp.Flags = sp.Flags | EscherSpRecord.FLAG_FLIPVERT; } anchor = CreateAnchor(userAnchor); clientData.RecordId = EscherClientDataRecord.RECORD_ID; clientData.Options = ((short)0x0000); spContainer.AddChildRecord(sp); spContainer.AddChildRecord(opt); spContainer.AddChildRecord(anchor); spContainer.AddChildRecord(clientData); return(spContainer); }
private static void DrawManyLines(HSSFPatriarch patriarch) { // Draw bunch of lines int x1 = 100; int y1 = 100; int x2 = 800; int y2 = 200; int color = 0; for (int i = 0; i < 10; i++) { HSSFClientAnchor a2 = new HSSFClientAnchor(); a2.SetAnchor((short)2, 2, x1, y1, (short)2, 2, x2, y2); HSSFSimpleShape shape2 = patriarch.CreateSimpleShape(a2); shape2.ShapeType = HSSFSimpleShape.OBJECT_TYPE_LINE; shape2.LineStyleColor = color; y1 -= 10; y2 -= 10; color += 30; } }
public void TestShapeEscherMustHaveAnchorRecord() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.CreateSheet() as HSSFSheet; HSSFPatriarch drawing = sheet.CreateDrawingPatriarch() as HSSFPatriarch; HSSFClientAnchor anchor = new HSSFClientAnchor(10, 10, 200, 200, (short)2, 2, (short)15, 15); anchor.AnchorType = (2); HSSFSimpleShape rectangle = drawing.CreateSimpleShape(anchor); rectangle.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_RECTANGLE); rectangle.Anchor = (anchor); Assert.IsNotNull(HSSFTestHelper.GetEscherAnchor(anchor)); Assert.IsNotNull(HSSFTestHelper.GetEscherContainer(rectangle)); Assert.IsTrue(HSSFTestHelper.GetEscherAnchor(anchor).Equals(HSSFTestHelper.GetEscherContainer(rectangle).GetChildById(EscherClientAnchorRecord.RECORD_ID))); }
public void TestCorrectOrderInSpContainer() { HSSFWorkbook wb = HSSFTestDataSamples.OpenSampleWorkbook("drawings.xls"); HSSFSheet sheet = wb.GetSheet("pictures") as HSSFSheet; HSSFPatriarch drawing = sheet.DrawingPatriarch as HSSFPatriarch; HSSFSimpleShape rectangle = (HSSFSimpleShape)drawing.Children[0]; Assert.AreEqual(HSSFTestHelper.GetEscherContainer(rectangle).GetChild(0).RecordId, EscherSpRecord.RECORD_ID); Assert.AreEqual(HSSFTestHelper.GetEscherContainer(rectangle).GetChild(1).RecordId, EscherOptRecord.RECORD_ID); Assert.AreEqual(HSSFTestHelper.GetEscherContainer(rectangle).GetChild(2).RecordId, EscherClientAnchorRecord.RECORD_ID); Assert.AreEqual(HSSFTestHelper.GetEscherContainer(rectangle).GetChild(3).RecordId, EscherClientDataRecord.RECORD_ID); rectangle.Anchor = (new HSSFClientAnchor()); Assert.AreEqual(HSSFTestHelper.GetEscherContainer(rectangle).GetChild(0).RecordId, EscherSpRecord.RECORD_ID); Assert.AreEqual(HSSFTestHelper.GetEscherContainer(rectangle).GetChild(1).RecordId, EscherOptRecord.RECORD_ID); Assert.AreEqual(HSSFTestHelper.GetEscherContainer(rectangle).GetChild(2).RecordId, EscherClientAnchorRecord.RECORD_ID); Assert.AreEqual(HSSFTestHelper.GetEscherContainer(rectangle).GetChild(3).RecordId, EscherClientDataRecord.RECORD_ID); }
private static void DrawGrid(HSSFPatriarch patriarch) { // This Draws a grid of lines. Since the coordinates space fixed at // 1024 by 256 we use a ratio to get a reasonably square grids. double xRatio = 3.22; double yRatio = 0.6711; int x1 = 000; int y1 = 000; int x2 = 000; int y2 = 200; for (int i = 0; i < 20; i++) { HSSFClientAnchor a2 = new HSSFClientAnchor(); a2.SetAnchor((short)2, 2, (int)(x1 * xRatio), (int)(y1 * yRatio), (short)2, 2, (int)(x2 * xRatio), (int)(y2 * yRatio)); HSSFSimpleShape shape2 = patriarch.CreateSimpleShape(a2); shape2.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_LINE); x1 += 10; x2 += 10; } x1 = 000; y1 = 000; x2 = 200; y2 = 000; for (int i = 0; i < 20; i++) { HSSFClientAnchor a2 = new HSSFClientAnchor(); a2.SetAnchor((short)2, 2, (int)(x1 * xRatio), (int)(y1 * yRatio), (short)2, 2, (int)(x2 * xRatio), (int)(y2 * yRatio)); HSSFSimpleShape shape2 = patriarch.CreateSimpleShape(a2); shape2.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_LINE); y1 += 10; y2 += 10; } }
/// <summary> /// Hàm vẽ một line căn vào giữa của 2 cột trên sheet /// </summary> /// <param name="sheet"></param> /// <param name="col1">Cột chứa điểm bắt đầu của line</param> /// <param name="row">Dòng chứa điểm bắt đầu của line</param> /// <param name="x">Tọa độ x của điểm bắt đầu (Tọa độ x trong 1 cell có giá trị từ 0 - 1023)</param> /// <param name="y">Tọa độ y của điểm bắt đầu (Tọa độ Y trong 1 cell có giá trị từ 0 - 255)</param> /// <param name="col2"></param> /// <modified> /// Author Date comment /// TuanVM 15/07/2012 Tạo mới /// </modified> public static void DrawLinesToCenter(this ISheet sheet, short col1, int row, int x, int y, short col2) { HSSFPatriarch patriarch = (HSSFPatriarch)sheet.CreateDrawingPatriarch(); HSSFClientAnchor a1 = new HSSFClientAnchor(); if (col2 == col1) { a1.SetAnchor(col1, row, x, y, col2, row, 1024 - x, y); } else { int col1Width = sheet.GetColumnWidth(col1); int col2Width = sheet.GetColumnWidth(col2); a1.SetAnchor(col1, row, x, y, col2, row, 1024 - x * col1Width / col2Width, y); } HSSFSimpleShape shape1 = patriarch.CreateSimpleShape(a1); shape1.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_LINE); }
private static void DrawSheet1(ISheet sheet1) { // Create a row and size one of the cells reasonably large. IRow row = sheet1.CreateRow(2); row.Height = ((short)2800); row.CreateCell(1); sheet1.SetColumnWidth(2, 9000); // Create the Drawing patriarch. This is the top level container for // all shapes. HSSFPatriarch patriarch = (HSSFPatriarch)sheet1.CreateDrawingPatriarch(); // Draw some lines and an oval. DrawLinesToCenter(patriarch); DrawManyLines(patriarch); DrawOval(patriarch); DrawPolygon(patriarch); // Draw a rectangle. HSSFSimpleShape rect = patriarch.CreateSimpleShape(new HSSFClientAnchor(100, 100, 900, 200, (short)0, 0, (short)0, 0)); rect.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_RECTANGLE); }
/// <summary> /// Creates the line shape from the highlevel user shape. All low level /// records are Created at this point. /// </summary> /// <param name="hssfShape">The user model shape</param> /// <param name="shapeId">The identifier to use for this shape.</param> public LineShape(HSSFSimpleShape hssfShape, int shapeId) { spContainer = CreateSpContainer(hssfShape, shapeId); objRecord = CreateObjRecord(hssfShape, shapeId); }
public static TextObjectRecord GetTextObjRecord(HSSFSimpleShape shape) { return(shape.GetTextObjectRecord()); }