PageOffice,word经常使用接口对象--Shape类

Shape类用来读取Word中的图形、图片,一个Shape对象表明Word中的一个图片。服务器

Shape类所属命名空间

  • Java开发时命名空间为:com.zhuozhengsoft.pageoffice.wordreader
  • ASP.NET开发时命名空间为:PageOffice.WordReader

Shape类的使用

在线编辑Word文件时,有时可能会须要读取或导出Word文件中的图形、图片,这时就须要经过Shape类来实现了,它能经过将Shape对象的saveAsJPG("saveAsFileName")方法将Word中的图形、图像保存成一个JPG图片文件。
Shape对象的获取可经过如下两种方法:spa

  1. 经过DataRegion对象获取,具体实现代码以下:

Java代码:code

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");//保存到服务器磁盘目录下
    ... ...
  1. 经过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"); //保存到服务器磁盘目录下
相关文章
相关标签/搜索