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 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(); } }