/// <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 = shape.SpContainer.GetChildById(EscherSpRecord.RECORD_ID); if (hssfShape.Parent != null) { sp.Flags = sp.Flags | EscherSpRecord.FLAG_CHILD; } return(shape); }
private static PictureSize CalculateSize(long length, PictureShape shape) { if (length > 1610546700) { throw new Exception("파일이 1.6GB보다 큽니다."); } if (shape == PictureShape.Square) { length /= 3; if ((Math.Sqrt(length) % 1) != 0) //소수 나옴 { int size = (int)Math.Ceiling(Math.Sqrt(length)); return(new PictureSize(size, size)); } else { int size = (int)Math.Sqrt(length); return(new PictureSize(size, size)); } } else if (shape == PictureShape.Rectangular) { int size = 0; if (((double)length / (double)3) % 1 != 0) //소수 나옴 { size = Convert.ToInt32(length); size /= 3; size += 1; } else { size = Convert.ToInt32(length); size /= 3; } List <Divisor> divisors = GetDivisors(size); for (int i = 0; i != divisors.Count; i++) { Console.WriteLine(i + " : w:" + divisors[i].A + " h:" + divisors[i].B); } int input = Convert.ToInt32(Console.ReadLine()); return(new PictureSize(divisors[input].A, divisors[input].B)); } else { length /= 3; int size = (int)Math.Ceiling(0.56419 * Math.Sqrt(length)); size *= 2; return(new PictureSize(size, size, true)); } }
public void TestShapeId() { HSSFClientAnchor anchor = new HSSFClientAnchor(); AbstractShape shape; CommonObjectDataSubRecord cmo; shape = new TextboxShape(new HSSFTextbox(null, anchor), 1025); cmo = (CommonObjectDataSubRecord)shape.ObjRecord.SubRecords[(0)]; Assert.AreEqual(1, cmo.ObjectId); shape = new PictureShape(new HSSFPicture(null, anchor), 1026); cmo = (CommonObjectDataSubRecord)shape.ObjRecord.SubRecords[(0)]; Assert.AreEqual(2, cmo.ObjectId); shape = new CommentShape(new HSSFComment(null, anchor), 1027); cmo = (CommonObjectDataSubRecord)shape.ObjRecord.SubRecords[(0)]; Assert.AreEqual(1027, cmo.ObjectId); }
static void Main(string[] args) { // Create spreadsheet Spreadsheet doc = new Spreadsheet(); // Add worksheet Worksheet worksheet = doc.Worksheets.Add(); // Put an image to "C3" cell PictureShape shape = worksheet.Pictures.Add(2, 2, "image1.jpg"); // Make the picture "floating". It will be not moved if you move or resize the "C3" cell shape.PlacementType = Placement.FreeFloating; // Make the picture brighter shape.Brightness = 0.8f; // Put second image to "K11" cell shape = worksheet.Pictures.Add(10, 10, "image2.jpg"); // Make the picture bound to the cell. It will be moved alonf with the "K11" cell shape.PlacementType = Placement.Move; // Crop 10% from left and right side of the image shape.CropFromLeft = 0.1f; shape.CropFromRight = 0.1f; // Delete output file if exists if (File.Exists("output.xls")) { File.Delete("output.xls"); } // Save document doc.SaveAs("output.xls"); // Close spreadsheet doc.Close(); // Open generated XLS document in default application Process.Start("output.xls"); doc.Dispose(); }
/// <summary> /// PPT产生缩略图 /// </summary> /// <param name="filePath"></param> /// <param name="previewPath"></param> /// <returns></returns> private static bool GetThumbnailPpt(string filePath, string previewPath) { bool result = false; Presentation ppt = new Presentation(); try { ppt.LoadFromFile(filePath); if (ppt.Slides.Count > 0) { //生成图片 foreach (IShape s in ppt.Slides[0].Shapes) { if (s is SlidePicture) { SlidePicture ps = s as SlidePicture; ps.PictureFill.Picture.EmbedImage.Image.Save(previewPath); if (File.Exists(previewPath)) { result = true; } ps.Dispose(); } if (s is PictureShape) { PictureShape ps = s as PictureShape; ps.EmbedImage.Image.Save(previewPath); if (File.Exists(previewPath)) { result = true; } } } if (!result) { string temImage = Path.GetDirectoryName(previewPath) + "\\" + Guid.NewGuid().ToString() + ".emf"; ppt.Slides[0].SaveAsEMF(temImage); Image image = Bitmap.FromFile(temImage); image.Save(previewPath); image.Dispose(); File.Delete(temImage); if (File.Exists(previewPath)) { result = true; } } if (!result) { result = GetThumbnailWritten("PPT", previewPath); } } ppt.Dispose(); } catch { ppt.Dispose(); result = GetThumbnailWritten("PPT", previewPath); } return(result); }