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对象的获取可通过以下两种方法:

  1. 通过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");//保存到服务器磁盘目录下
    ... ...
  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"); //保存到服务器磁盘目录下

转载于:https://my.oschina.net/u/3850288/blog/2046299

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值