Shape类用来读取Word中的图形、图片,一个Shape对象代表Word中的一个图片。
Shape类所属命名空间
- Java开发时命名空间为:com.zhuozhengsoft.pageoffice.wordreader
- ASP.NET开发时命名空间为:PageOffice.WordReader
Shape类的使用
在线编辑Word文件时,有时可能会需要读取或导出Word文件中的图形、图片,这时就需要通过Shape类来实现了,它能通过将Shape对象的saveAsJPG("saveAsFileName")方法将Word中的图形、图像保存成一个JPG图片文件。
Shape对象的获取可通过以下两种方法:
- 通过DataRegion对象获取,具体实现代码如下:
Java代码:
WordDocument doc = new WordDocument(request,response);//注意参数
DataRegion dataRegion = doc.openDataRegion("PO_img");
Shape shape = dataRegion.openShape(1); //参数为Word中Shape的索引,从“1”开始
shape.saveAsJPG("D:\\test.jpg");//保存到服务器磁盘目录下
... ...
ASP.NET代码:
WordDocument doc = new WordDocument();
DataRegion dataRegion = doc.OpenDataRegion("PO_img");
Shape shape = dataRegion.OpenShape(1); //参数为Word中Shape的索引,从“1”开始
shape.SaveAsJPG("D:\\test.jpg");//保存到服务器磁盘目录下
... ...
- 通过Cell对象获取,具体实现代码如下:
Java代码:
... ...
Cell cell = table.openCellRC(2,3); //获取某个Cell对象
//List<Shape> shapes = cell.getShapes(); //获取Cell里包含的 Shape 集合
//Shape shape = shapes.get(index); //获取集合中的某个Shape对象
Shape shape = cell.openShape(1); //获取Cell中的某个Shape对象,索引从“1”开始
shape.saveAsJPG("D:\\test.jpg"); //保存到服务器磁盘目录下
... ...
ASP.NET代码:
... ...
Cell cell = table.OpenCellRC(2,3); //获取某个Cell对象
//ArrayList shapes = cell.Shapes; //获取Cell里包含的 Shape 集合
//Shape shape = shapes[index]; //获取集合中的某个Shape对象
Shape shape = cell.OpenShape(1); //获取Cell中的某个Shape对象,索引从“1”开始
shape.SaveAsJPG("D:\\test.jpg"); //保存到服务器磁盘目录下