/// <summary> /// Creates the low level OBJ record for this shape. /// </summary> /// <param name="hssfShape">The HSSFShape.</param> /// <param name="shapeId">The shape id.</param> /// <returns></returns> private ObjRecord CreateObjRecord(HSSFShape hssfShape, int shapeId) { HSSFShape shape = hssfShape; ObjRecord obj = new ObjRecord(); CommonObjectDataSubRecord c = new CommonObjectDataSubRecord(); c.ObjectType = (CommonObjectType)((HSSFSimpleShape)shape).ShapeType; // c.ObjectId((short) ( 1 )); c.ObjectId = GetCmoObjectId(shapeId); c.IsLocked = true; c.IsPrintable = true; c.IsAutoFill = true; c.IsAutoline = true; // c.Reserved2( 0x012C0A84 ); c.Reserved2 = (0x0); // UnknownRecord sub1 = new UnknownRecord( (short)0x7, (short)0x2, new byte[] { 0x09, 0x00 } ); // UnknownRecord sub2 = new UnknownRecord( (short)0x8, (short)0x2, new byte[] { 0x01, 0x00 } ); EndSubRecord e = new EndSubRecord(); obj.AddSubRecord(c); // obj.AddSubRecord( sub1 ); // obj.AddSubRecord( sub2 ); obj.AddSubRecord(e); return(obj); }
/// <summary> /// Sets standard escher options for a comment. /// This method is responsible for Setting default background, /// shading and other comment properties. /// </summary> /// <param name="shape">The highlevel shape.</param> /// <param name="opt">The escher records holding the proerties</param> /// <returns>The number of escher options added</returns> protected override int AddStandardOptions(HSSFShape shape, EscherOptRecord opt) { base.AddStandardOptions(shape, opt); //Remove Unnecessary properties inherited from TextboxShape for (int i = 0; i < opt.EscherProperties.Count; i++) { EscherProperty prop = opt.EscherProperties[i]; switch (prop.Id) { case EscherProperties.TEXT__TEXTLEFT: case EscherProperties.TEXT__TEXTRIGHT: case EscherProperties.TEXT__TEXTTOP: case EscherProperties.TEXT__TEXTBOTTOM: case EscherProperties.GROUPSHAPE__PRINT: case EscherProperties.Fill__FillBACKCOLOR: case EscherProperties.LINESTYLE__COLOR: opt.EscherProperties.Remove(prop); i--; break; } } HSSFComment comment = (HSSFComment)shape; opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.GROUPSHAPE__PRINT, comment.Visible ? 0x000A0000 : 0x000A0002)); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.SHADOWSTYLE__SHADOWOBSURED, 0x00030003)); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.SHADOWSTYLE__COLOR, 0x00000000)); opt.SortProperties(); return(opt.EscherProperties.Count); // # options Added }
/// <summary> /// Sets standard escher options for a comment. /// This method is responsible for Setting default background, /// shading and other comment properties. /// </summary> /// <param name="shape">The highlevel shape.</param> /// <param name="opt">The escher records holding the proerties</param> /// <returns>The number of escher options added</returns> protected override int AddStandardOptions(HSSFShape shape, EscherOptRecord opt) { base.AddStandardOptions(shape, opt); //Remove Unnecessary properties inherited from TextboxShape IList props = (IList)opt.EscherProperties.Clone(); for (IEnumerator iterator = props.GetEnumerator(); iterator.MoveNext();) { EscherProperty prop = (EscherProperty)iterator.Current; switch (prop.Id) { case EscherProperties.TEXT__TEXTLEFT: case EscherProperties.TEXT__TEXTRIGHT: case EscherProperties.TEXT__TEXTTOP: case EscherProperties.TEXT__TEXTBOTTOM: case EscherProperties.GROUPSHAPE__PRINT: case EscherProperties.Fill__FillBACKCOLOR: case EscherProperties.LINESTYLE__COLOR: opt.EscherProperties.Remove(prop); break; } } HSSFComment comment = (HSSFComment)shape; opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.GROUPSHAPE__PRINT, comment.Visible ? 0x000A0000 : 0x000A0002)); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.SHADOWSTYLE__SHADOWOBSURED, 0x00030003)); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.SHADOWSTYLE__COLOR, 0x00000000)); opt.SortProperties(); return(opt.EscherProperties.Count); // # options Added }
/// <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); }
/// <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 List <object> GetShapes(ISheet sheet) { List <object> list = new List <object>(); IDrawing drawingPatriarch = sheet.DrawingPatriarch; if (sheet is HSSFSheet) { HSSFShapeContainer hSSFShapeContainer = sheet.DrawingPatriarch as HSSFShapeContainer; if (drawingPatriarch == null) { return(list); } IList <HSSFShape> children = hSSFShapeContainer.Children; using (IEnumerator <HSSFShape> enumerator = children.GetEnumerator()) { while (enumerator.MoveNext()) { HSSFShape current = enumerator.Current; if (current != null && current.Anchor is HSSFClientAnchor) { HSSFClientAnchor hSSFClientAnchor = current.Anchor as HSSFClientAnchor; if (this.IsInternalOrIntersect(this.ShapeRange.MinRow, this.ShapeRange.MaxRow, this.ShapeRange.MinColumn, this.ShapeRange.MaxColumn, hSSFClientAnchor.Row1, hSSFClientAnchor.Row2, hSSFClientAnchor.Col1, hSSFClientAnchor.Col2, true)) { list.Add(current); } } } return(list); } } List <POIXMLDocumentPart> relations = (sheet as XSSFSheet).GetRelations(); foreach (POIXMLDocumentPart current2 in relations) { if (current2 is XSSFDrawing) { XSSFDrawing xSSFDrawing = (XSSFDrawing)current2; List <XSSFShape> shapes = xSSFDrawing.GetShapes(); foreach (XSSFShape current3 in shapes) { XSSFAnchor anchor = current3.GetAnchor(); if (current3 != null && anchor is XSSFClientAnchor) { XSSFClientAnchor xSSFClientAnchor = anchor as XSSFClientAnchor; if (this.IsInternalOrIntersect(this.ShapeRange.MinRow, this.ShapeRange.MaxRow, this.ShapeRange.MinColumn, this.ShapeRange.MaxColumn, xSSFClientAnchor.Row1, xSSFClientAnchor.Row2, xSSFClientAnchor.Col1, xSSFClientAnchor.Col2, true)) { list.Add(current3); } } } } } return(list); }
/// <summary> /// Creates the low level OBJ record for this shape. /// </summary> /// <param name="hssfShape">The HSSF shape.</param> /// <param name="shapeId">The shape id.</param> /// <returns></returns> private ObjRecord CreateObjRecord(HSSFShape hssfShape, int shapeId) { HSSFShape shape = hssfShape; ObjRecord obj = new ObjRecord(); CommonObjectDataSubRecord c = new CommonObjectDataSubRecord(); c.ObjectType = (CommonObjectType)((HSSFSimpleShape)shape).ShapeType; c.ObjectId = GetCmoObjectId(shapeId); c.IsLocked = true; c.IsPrintable = true; c.IsAutoFill = true; c.IsAutoline = true; EndSubRecord e = new EndSubRecord(); obj.AddSubRecord(c); obj.AddSubRecord(e); return obj; }
/// <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); }
/// <summary> /// Creates the lowerlevel OBJ records for this shape. /// </summary> /// <param name="hssfShape">The HSSF shape.</param> /// <param name="shapeId">The shape id.</param> /// <returns></returns> private ObjRecord CreateObjRecord(HSSFShape hssfShape, int shapeId) { HSSFShape shape = hssfShape; ObjRecord obj = new ObjRecord(); CommonObjectDataSubRecord c = new CommonObjectDataSubRecord(); c.ObjectType = CommonObjectType.MICROSOFT_OFFICE_DRAWING; c.ObjectId = ((short)(shapeId)); c.IsLocked = (true); c.IsPrintable = (true); c.IsAutoFill = (true); c.IsAutoline = (true); EndSubRecord e = new EndSubRecord(); obj.AddSubRecord(c); obj.AddSubRecord(e); return(obj); }
/// <summary> /// Creates the lowerlevel OBJ records for this shape. /// </summary> /// <param name="hssfShape">The HSSF shape.</param> /// <param name="shapeId">The shape id.</param> /// <returns></returns> private ObjRecord CreateObjRecord(HSSFShape hssfShape, int shapeId) { HSSFShape shape = hssfShape; ObjRecord obj = new ObjRecord(); CommonObjectDataSubRecord c = new CommonObjectDataSubRecord(); c.ObjectType = (CommonObjectType)OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING; c.ObjectId = GetCmoObjectId(shapeId); c.IsLocked = true; c.IsPrintable = true; c.IsAutoFill = true; c.IsAutoline = true; EndSubRecord e = new EndSubRecord(); obj.AddSubRecord(c); obj.AddSubRecord(e); return(obj); }
/// <summary> /// Creates the lowerlevel OBJ records for this shape. /// </summary> /// <param name="hssfShape">The HSSF shape.</param> /// <param name="shapeId">The shape id.</param> /// <returns></returns> private ObjRecord CreateObjRecord(HSSFTextbox hssfShape, int shapeId) { HSSFShape shape = hssfShape; ObjRecord obj = new ObjRecord(); CommonObjectDataSubRecord c = new CommonObjectDataSubRecord(); c.ObjectType = (CommonObjectType)((HSSFSimpleShape)shape).ShapeType; c.ObjectId = ((short)(shapeId)); c.IsLocked = (true); c.IsPrintable = (true); c.IsAutoFill = (true); c.IsAutoline = (true); EndSubRecord e = new EndSubRecord(); obj.AddSubRecord(c); obj.AddSubRecord(e); return(obj); }
public override void Format(SheetAdapter sheetAdapter) { ISheet currentSheet = sheetAdapter.CurrentSheet; List <object> shapes = this.PictureInfo.GetShapes(currentSheet); bool flag = false; if (currentSheet is HSSFSheet) { flag = true; } if (shapes == null || shapes.Count <= 0) { throw new Exception(string.Format("未能获取到工作薄[{0}]指定区域的图形对象列表!", currentSheet.SheetName)); } byte[] pictureData = File.ReadAllBytes(this.PictureInfo.FilePath); IClientAnchor anchor; IDrawing drawing; if (flag) { HSSFShape hSSFShape = shapes[0] as HSSFShape; anchor = (hSSFShape.Anchor as IClientAnchor); drawing = hSSFShape.Patriarch; hSSFShape.LineStyle = LineStyle.None; } else { XSSFShape xSSFShape = shapes[0] as XSSFShape; anchor = (xSSFShape.GetAnchor() as IClientAnchor); drawing = xSSFShape.GetDrawing(); xSSFShape.LineStyle = LineStyle.None; } int pictureIndex = currentSheet.Workbook.AddPicture(pictureData, this.PictureInfo.PictureType); IPicture picture = drawing.CreatePicture(anchor, pictureIndex); if (this.PictureInfo.AutoSize) { picture.Resize(); } }
/// <summary> /// Add standard properties to the opt record. These properties effect /// all records. /// </summary> /// <param name="shape">The user model shape.</param> /// <param name="opt">The opt record to Add the properties to.</param> /// <returns>The number of options Added.</returns> protected virtual int AddStandardOptions(HSSFShape shape, EscherOptRecord opt) { opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x080000)); // opt.AddEscherProperty( new EscherBoolProperty( EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x080008 ) ); if (shape.IsNoFill) { // Wonderful... none of the spec's give any clue as to what these constants mean. opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, 0x00110000)); } else { opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, 0x00010000)); } opt.AddEscherProperty(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, shape.FillColor)); opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.GROUPSHAPE__PRINT, 0x080000)); opt.AddEscherProperty(new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, shape.LineStyleColor)); int options = 5; if (shape.LineWidth != HSSFShape.LINEWIDTH_DEFAULT) { opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEWIDTH, shape.LineWidth)); options++; } if (shape.LineStyle != LineStyle.Solid) { opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEDASHING, (int)shape.LineStyle)); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEENDCAPSTYLE, 0)); if (shape.LineStyle == LineStyle.None) { opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080000)); } else { opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080008)); } options += 3; } opt.SortProperties(); return(options); // # options Added }
private void ConvertShapes(HSSFShapeContainer parent, EscherContainerRecord escherParent, Hashtable shapeToObj) { if (escherParent == null) { throw new ArgumentException("Parent record required"); } IList shapes = parent.Children; for (IEnumerator iterator = shapes.GetEnumerator(); iterator.MoveNext();) { HSSFShape shape = (HSSFShape)iterator.Current; if (shape is HSSFShapeGroup) { ConvertGroup((HSSFShapeGroup)shape, escherParent, shapeToObj); } else { AbstractShape shapeModel = AbstractShape.CreateShape( shape, drawingManager.AllocateShapeId(drawingGroupId)); shapeToObj[FindClientData(shapeModel.SpContainer)] = shapeModel.ObjRecord; if (shapeModel is TextboxShape) { EscherRecord escherTextbox = ((TextboxShape)shapeModel).EscherTextbox; shapeToObj[escherTextbox] = ((TextboxShape)shapeModel).TextObjectRecord; // escherParent.AddChildRecord(escherTextbox); if (shapeModel is CommentShape) { CommentShape comment = (CommentShape)shapeModel; tailRec.Add(comment.NoteRecord); } } escherParent.AddChildRecord(shapeModel.SpContainer); } } // drawingManager.newCluster( (short)1 ); // drawingManager.newCluster( (short)2 ); }
/// <summary> /// HSSFSheet清除指定区域的图片 /// </summary> /// <param name="sheet"></param> /// <param name="minRow"></param> /// <param name="maxRow"></param> /// <param name="minCol"></param> /// <param name="maxCol"></param> /// <param name="onlyInternal"></param> private static void RemovePictures(HSSFSheet sheet, int?minRow, int?maxRow, int?minCol, int?maxCol, bool onlyInternal) { var shapeContainer = sheet.DrawingPatriarch as HSSFShapeContainer; if (null != shapeContainer) { IList <HSSFShape> shapeList = shapeContainer.Children; for (int i = 0; i < shapeList.Count; i++) { HSSFShape shape = shapeList[i]; if (shape is HSSFPicture && shape.Anchor is HSSFClientAnchor) { var picture = (HSSFPicture)shape; var anchor = (HSSFClientAnchor)shape.Anchor; if (IsInternalOrIntersect(minRow, maxRow, minCol, maxCol, anchor.Row1, anchor.Row2, anchor.Col1, anchor.Col2, onlyInternal)) { shapeContainer.RemoveShape(shape); } } } } }
public static EscherContainerRecord GetEscherContainer(HSSFShape shape) { return(shape.GetEscherContainer()); }
public static void SetShapeId(HSSFShape shape, int id) { shape.ShapeId = (id); }
public static EscherOptRecord GetOptRecord(HSSFShape shape) { return(shape.GetOptRecord()); }
public static ObjRecord GetObjRecord(HSSFShape shape) { return(shape.GetObjRecord()); }
private void ConvertRecordsToUserModel(EscherContainerRecord shapeContainer, Object model) { for (IEnumerator it = shapeContainer.ChildRecords.GetEnumerator(); it.MoveNext();) { EscherRecord r = (EscherRecord)it.Current; if (r is EscherSpgrRecord) { // This may be overriden by a later EscherClientAnchorRecord EscherSpgrRecord spgr = (EscherSpgrRecord)r; if (model is HSSFShapeGroup) { HSSFShapeGroup g = (HSSFShapeGroup)model; g.SetCoordinates( spgr.RectX1, spgr.RectY1, spgr.RectX2, spgr.RectY2 ); } else { throw new InvalidOperationException("Got top level anchor but not Processing a Group"); } } else if (r is EscherClientAnchorRecord) { EscherClientAnchorRecord car = (EscherClientAnchorRecord)r; if (model is HSSFShape) { HSSFShape g = (HSSFShape)model; g.Anchor.Dx1 = car.Dx1; g.Anchor.Dx2 = car.Dx2; g.Anchor.Dy1 = car.Dy1; g.Anchor.Dy2 = car.Dy2; } else { throw new InvalidOperationException("Got top level anchor but not Processing a Group or shape"); } } else if (r is EscherTextboxRecord) { EscherTextboxRecord tbr = (EscherTextboxRecord)r; // Also need to Find the TextObjectRecord too // TODO } else if (r is EscherSpRecord) { // Use flags if needed } else if (r is EscherOptRecord) { // Use properties if needed } else { //Console.Error.WriteLine(r); } } }
/// <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(HSSFPolygon 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; sp.Options = (short)((EscherAggregate.ST_DONUT << 4) | 0x2); sp.ShapeId = shapeId; if (hssfShape.Parent == null) { sp.Flags = EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE; } else { sp.Flags = EscherSpRecord.FLAG_CHILD | EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE; } opt.RecordId = EscherOptRecord.RECORD_ID; opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TRANSFORM__ROTATION, false, false, 0)); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__RIGHT, false, false, hssfShape.DrawAreaWidth)); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__BOTTOM, false, false, hssfShape.DrawAreaHeight)); opt.AddEscherProperty(new EscherShapePathProperty(EscherProperties.GEOMETRY__SHAPEPATH, EscherShapePathProperty.COMPLEX)); EscherArrayProperty verticesProp = new EscherArrayProperty(EscherProperties.GEOMETRY__VERTICES, false, new byte[0]); verticesProp.NumberOfElementsInArray = (hssfShape.XPoints.Length + 1); verticesProp.NumberOfElementsInMemory = (hssfShape.XPoints.Length + 1); verticesProp.SizeOfElements = unchecked ((short)0xFFF0); for (int i = 0; i < hssfShape.XPoints.Length; i++) { byte[] data = new byte[4]; LittleEndian.PutShort(data, 0, (short)hssfShape.XPoints[i]); LittleEndian.PutShort(data, 2, (short)hssfShape.YPoints[i]); verticesProp.SetElement(i, data); } int point = hssfShape.XPoints.Length; byte[] data1 = new byte[4]; LittleEndian.PutShort(data1, 0, (short)hssfShape.XPoints[0]); LittleEndian.PutShort(data1, 2, (short)hssfShape.YPoints[0]); verticesProp.SetElement(point, data1); opt.AddEscherProperty(verticesProp); EscherArrayProperty segmentsProp = new EscherArrayProperty(EscherProperties.GEOMETRY__SEGMENTINFO, false, null); segmentsProp.SizeOfElements = (0x0002); segmentsProp.NumberOfElementsInArray = (hssfShape.XPoints.Length * 2 + 4); segmentsProp.NumberOfElementsInMemory = (hssfShape.XPoints.Length * 2 + 4); segmentsProp.SetElement(0, new byte[] { (byte)0x00, (byte)0x40 }); segmentsProp.SetElement(1, new byte[] { (byte)0x00, (byte)0xAC }); for (int i = 0; i < hssfShape.XPoints.Length; i++) { segmentsProp.SetElement(2 + i * 2, new byte[] { (byte)0x01, (byte)0x00 }); segmentsProp.SetElement(3 + i * 2, new byte[] { (byte)0x00, (byte)0xAC }); } segmentsProp.SetElement(segmentsProp.NumberOfElementsInArray - 2, new byte[] { (byte)0x01, (byte)0x60 }); segmentsProp.SetElement(segmentsProp.NumberOfElementsInArray - 1, new byte[] { (byte)0x00, (byte)0x80 }); opt.AddEscherProperty(segmentsProp); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__FillOK, false, false, 0x00010001)); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINESTARTARROWHEAD, false, false, 0x0)); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEENDARROWHEAD, false, false, 0x0)); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEENDCAPSTYLE, false, false, 0x0)); 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 TestRemoveShapes() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sheet.CreateDrawingPatriarch() as HSSFPatriarch; HSSFSimpleShape rectangle = patriarch.CreateSimpleShape(new HSSFClientAnchor()); rectangle.ShapeType = HSSFSimpleShape.OBJECT_TYPE_RECTANGLE; int idx = wb.AddPicture(new byte[] { 1, 2, 3 }, PictureType.JPEG); patriarch.CreatePicture(new HSSFClientAnchor(), idx); patriarch.CreateCellComment(new HSSFClientAnchor()); HSSFPolygon polygon = patriarch.CreatePolygon(new HSSFClientAnchor()); polygon.SetPoints(new int[] { 1, 2 }, new int[] { 2, 3 }); patriarch.CreateTextbox(new HSSFClientAnchor()); HSSFShapeGroup group = patriarch.CreateGroup(new HSSFClientAnchor()); group.CreateTextbox(new HSSFChildAnchor()); group.CreatePicture(new HSSFChildAnchor(), idx); Assert.AreEqual(patriarch.Children.Count, 6); Assert.AreEqual(group.Children.Count, 2); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 12); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1); wb = HSSFTestDataSamples.WriteOutAndReadBack(wb); sheet = wb.GetSheetAt(0) as HSSFSheet; patriarch = sheet.DrawingPatriarch as HSSFPatriarch; Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 12); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1); Assert.AreEqual(patriarch.Children.Count, 6); group = (HSSFShapeGroup)patriarch.Children[5]; group.RemoveShape(group.Children[0]); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 10); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1); wb = HSSFTestDataSamples.WriteOutAndReadBack(wb); sheet = wb.GetSheetAt(0) as HSSFSheet; patriarch = sheet.DrawingPatriarch as HSSFPatriarch; Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 10); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1); group = (HSSFShapeGroup)patriarch.Children[(5)]; patriarch.RemoveShape(group); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 8); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1); wb = HSSFTestDataSamples.WriteOutAndReadBack(wb); sheet = wb.GetSheetAt(0) as HSSFSheet; patriarch = sheet.DrawingPatriarch as HSSFPatriarch; Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 8); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1); Assert.AreEqual(patriarch.Children.Count, 5); HSSFShape shape = patriarch.Children[0]; patriarch.RemoveShape(shape); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 6); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1); Assert.AreEqual(patriarch.Children.Count, 4); wb = HSSFTestDataSamples.WriteOutAndReadBack(wb); sheet = wb.GetSheetAt(0) as HSSFSheet; patriarch = sheet.DrawingPatriarch as HSSFPatriarch; Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 6); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1); Assert.AreEqual(patriarch.Children.Count, 4); HSSFPicture picture = (HSSFPicture)patriarch.Children[0]; patriarch.RemoveShape(picture); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 5); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1); Assert.AreEqual(patriarch.Children.Count, 3); wb = HSSFTestDataSamples.WriteOutAndReadBack(wb); sheet = wb.GetSheetAt(0) as HSSFSheet; patriarch = sheet.DrawingPatriarch as HSSFPatriarch; Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 5); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 1); Assert.AreEqual(patriarch.Children.Count, 3); HSSFComment comment = (HSSFComment)patriarch.Children[0]; patriarch.RemoveShape(comment); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 3); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 0); Assert.AreEqual(patriarch.Children.Count, 2); wb = HSSFTestDataSamples.WriteOutAndReadBack(wb); sheet = wb.GetSheetAt(0) as HSSFSheet; patriarch = sheet.DrawingPatriarch as HSSFPatriarch; Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 3); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 0); Assert.AreEqual(patriarch.Children.Count, 2); polygon = (HSSFPolygon)patriarch.Children[0]; patriarch.RemoveShape(polygon); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 2); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 0); Assert.AreEqual(patriarch.Children.Count, 1); wb = HSSFTestDataSamples.WriteOutAndReadBack(wb); sheet = wb.GetSheetAt(0) as HSSFSheet; patriarch = sheet.DrawingPatriarch as HSSFPatriarch; Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 2); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 0); Assert.AreEqual(patriarch.Children.Count, 1); HSSFTextbox textbox = (HSSFTextbox)patriarch.Children[0]; patriarch.RemoveShape(textbox); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 0); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 0); Assert.AreEqual(patriarch.Children.Count, 0); wb = HSSFTestDataSamples.WriteOutAndReadBack(wb); sheet = wb.GetSheetAt(0) as HSSFSheet; patriarch = sheet.DrawingPatriarch as HSSFPatriarch; Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).GetShapeToObjMapping().Count, 0); Assert.AreEqual(HSSFTestHelper.GetEscherAggregate(patriarch).TailRecords.Count, 0); Assert.AreEqual(patriarch.Children.Count, 0); }
private void CheckWorkbookBack(HSSFWorkbook wb) { HSSFWorkbook wbBack = HSSFTestDataSamples.WriteOutAndReadBack(wb); Assert.IsNotNull(wbBack); HSSFSheet sheetBack = wbBack.GetSheetAt(0) as HSSFSheet; Assert.IsNotNull(sheetBack); HSSFPatriarch patriarchBack = sheetBack.DrawingPatriarch as HSSFPatriarch; Assert.IsNotNull(patriarchBack); IList <HSSFShape> children = patriarchBack.Children; Assert.AreEqual(4, children.Count); HSSFShape hssfShape = children[(0)]; Assert.IsTrue(hssfShape is HSSFSimpleShape); HSSFAnchor anchor = hssfShape.Anchor; Assert.IsTrue(anchor is HSSFClientAnchor); Assert.AreEqual(0, anchor.Dx1); Assert.AreEqual(512, anchor.Dx2); Assert.AreEqual(0, anchor.Dy1); Assert.AreEqual(100, anchor.Dy2); HSSFClientAnchor cAnchor = (HSSFClientAnchor)anchor; Assert.AreEqual(1, cAnchor.Col1); Assert.AreEqual(1, cAnchor.Col2); Assert.AreEqual(1, cAnchor.Row1); Assert.AreEqual(1, cAnchor.Row2); hssfShape = children[(1)]; Assert.IsTrue(hssfShape is HSSFSimpleShape); anchor = hssfShape.Anchor; Assert.IsTrue(anchor is HSSFClientAnchor); Assert.AreEqual(512, anchor.Dx1); Assert.AreEqual(1023, anchor.Dx2); Assert.AreEqual(0, anchor.Dy1); Assert.AreEqual(100, anchor.Dy2); cAnchor = (HSSFClientAnchor)anchor; Assert.AreEqual(1, cAnchor.Col1); Assert.AreEqual(1, cAnchor.Col2); Assert.AreEqual(1, cAnchor.Row1); Assert.AreEqual(1, cAnchor.Row2); hssfShape = children[(2)]; Assert.IsTrue(hssfShape is HSSFSimpleShape); anchor = hssfShape.Anchor; Assert.IsTrue(anchor is HSSFClientAnchor); Assert.AreEqual(0, anchor.Dx1); Assert.AreEqual(512, anchor.Dx2); Assert.AreEqual(0, anchor.Dy1); Assert.AreEqual(100, anchor.Dy2); cAnchor = (HSSFClientAnchor)anchor; Assert.AreEqual(2, cAnchor.Col1); Assert.AreEqual(2, cAnchor.Col2); Assert.AreEqual(2, cAnchor.Row1); Assert.AreEqual(2, cAnchor.Row2); hssfShape = children[(3)]; Assert.IsTrue(hssfShape is HSSFSimpleShape); anchor = hssfShape.Anchor; Assert.IsTrue(anchor is HSSFClientAnchor); Assert.AreEqual(0, anchor.Dx1); Assert.AreEqual(512, anchor.Dx2); Assert.AreEqual(100, anchor.Dy1); Assert.AreEqual(200, anchor.Dy2); cAnchor = (HSSFClientAnchor)anchor; Assert.AreEqual(2, cAnchor.Col1); Assert.AreEqual(2, cAnchor.Col2); Assert.AreEqual(2, cAnchor.Row1); Assert.AreEqual(2, cAnchor.Row2); }