操作 Word 文档中图片,包括获取、添加、删除和更新图片。
接口方法 1:getImages() 获取指定段落中的图片
HTTP 请求方法:GET
请求 URL:https://api.e-iceblue.cn/v1/word/document/{name}/images
请求参数:
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
name | 是 | string | 原文档名称 | |
folder | 否 | string | 存放原文档的文件夹,没有则为null | |
storage | 否 | string | 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null | |
password | 否 | string | 原文档密码,没有则为null | |
paragraphPath | 是 | string | 含有图片的段落路径,如果省略该参数,则默认为文档的根目录 |
代码示例:
- .NET
- Java
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client;
namespace GetImageFormat
{
class Program
{
static string appId = "your id";
static string appKey = "your key";
static string baseUrl = "https://api.e-iceblue.cn";
static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
static ImagesApi imagesApi = new ImagesApi(wordConfiguration);
static void Main(string[] args)
{
string name = "getImageFormat.docx"; ;
string paragraphPath = "Section/0/Body/0/Paragraph/1";
int index = 0;
string folder = "input";
string storage = null;
string password = null;
imagesApi.GetImageFormat(name, paragraphPath, index, password, folder, storage);
}
}
}
import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.ImagesApi;
public class GetImage {
static String appId = "your id";
static String appKey = "your key";
static String baseUrl = "https://api.e-iceblue.cn";
static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
static ImagesApi imagesApi = new ImagesApi(wordConfiguration);
public static void main(String[] args) throws ApiException {
String name = "getImages.docx";
String paragraphPath = "Section/0/Body/0/Paragraph/1";
String folder = "input";
String storage = null;
String password = null;
imagesApi.getImages(name, password, folder, storage, paragraphPath);
}
}
接口方法 2:addImageInRequest() 添加图片到指定段落
HTTP 请求方法:POST
请求 URL:https://api.e-iceblue.cn/v1/word/document/{name}/{paragraphPath}/addImageInRequest
请求参数:
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
name | 是 | string | 原文档名称 | |
folder | 否 | string | 存放原文档的文件夹,没有则为null | |
storage | 否 | string | 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null | |
password | 否 | string | 原文档密码,没有则为null | |
paragraphPath | 是 | string | 含有图片的段落路径,如果省略该参数,则默认为文档的根目录 | |
inputImage | 是 | file | 图片文件 | |
indexInParagraph | 否 | integer | 添加图片的段落的索引 | |
destFilePath | 是 | string | 结果文档的存贮路径,如果省略该参数,则默认存到根目录 |
代码示例:
- .NET
- Java
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client;
using System.IO;
namespace AddImageInRequest
{
class Program
{
static string appId = "your id";
static string appKey = "your key";
static string baseUrl = "https://api.e-iceblue.cn";
static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
static ImagesApi imagesApi = new ImagesApi(wordConfiguration);
static void Main(string[] args)
{
string name = "addImage.docx";
Stream inputImage = new FileStream("../../inputFile/image.png", FileMode.Open);
string paragraphPath = "Section/0/Body/0/Paragraph/0";
string folder = "input";
string storage = null;
string password = null;
int indexInParagraph = 0;
string destFilePath = "output/addImage_out.docx";
imagesApi.AddImageInRequest(name, inputImage, paragraphPath, destFilePath, folder, storage, password, indexInParagraph);
}
}
}
import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.ImagesApi;
import java.io.File;
public class AddImageInRequest {
static String appId = "your id";
static String appKey = "your key";
static String baseUrl = "https://api.e-iceblue.cn";
static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
static ImagesApi imagesApi = new ImagesApi(wordConfiguration);
public static void main(String[] args) throws ApiException {
String name = "addImage.docx";
File inputImage = new File("../../inputFile/image.png");
String paragraphPath = "Section/0/Body/0/Paragraph/0";
String folder = "input";
String storage = null;
String password = null;
Integer indexInParagraph = 0;
String destFilePath = "output/addImage_out.docx";
imagesApi.addImageInRequest(name, inputImage, paragraphPath, destFilePath, folder, storage, password, indexInParagraph);
}
}
接口方法 3:addImage() 添加图片到指定段落
HTTP 请求方法:POST
请求 URL:https://api.e-iceblue.cn/v1/word/document/{name}/{paragraphPath}/addImage
请求参数:
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
name | 是 | string | 原文档名称 | |
folder | 否 | string | 存放原文档的文件夹,没有则为null | |
storage | 否 | string | 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null | |
password | 否 | string | 原文档密码,没有则为null | |
paragraphPath | 是 | string | 含有图片的段落路径,如果省略该参数,则默认为文档的根目录 | |
imagePath | 是 | string | 图片文件的路径 | |
indexInParagraph | 否 | integer | 添加图片的段落的索引 | |
destFilePath | 是 | string | 结果文档的存贮路径,如果省略该参数,则默认存到根目录 |
代码示例:
- .NET
- Java
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client;
namespace AddImage
{
class Program
{
static string appId = "your id";
static string appKey = "your key";
static string baseUrl = "https://api.e-iceblue.cn";
static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
static ImagesApi imagesApi = new ImagesApi(wordConfiguration);
static void Main(string[] args)
{
string name = "addImage.docx";
string imagePath = "input/image.png";
string paragraphPath = "Section/0/Body/0/Paragraph/0";
string folder = "input";
string storage = null;
string password = null;
int indexInParagraph = 0;
string destFilePath = "output/addImage_out.docx";
imagesApi.AddImage(name, imagePath, paragraphPath, destFilePath, folder, storage, password, indexInParagraph);
}
}
}
import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.ImagesApi;
import java.io.File;
public class AddImage {
static String appId = "your id";
static String appKey = "your key";
static String baseUrl = "https://api.e-iceblue.cn";
static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
static ImagesApi imagesApi = new ImagesApi(wordConfiguration);
public static void main(String[] args) throws ApiException {
String name = "addImage.docx";
String imagePath = "input/image.png";
String paragraphPath = "Section/0/Body/0/Paragraph/0";
String folder = "input";
String storage = null;
String password = null;
Integer indexInParagraph = 0;
String destFilePath = "output/addImage_out.docx";
imagesApi.addImage(name, imagePath, paragraphPath, destFilePath, folder, storage, password, indexInParagraph);
}
}
接口方法 4:deleteImage() 删除指定段落的图片
HTTP 请求方法:DELETE
请求 URL:https://api.e-iceblue.cn/v1/word/document/{name}/{paragraphPath}/images/{index}
请求参数:
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
name | 是 | string | 原文档名称 | |
folder | 否 | string | 存放原文档的文件夹,没有则为null | |
storage | 否 | string | 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null | |
password | 否 | string | 原文档密码,没有则为null | |
paragraphPath | 是 | string | 含有图片的段落路径,如果省略该参数,则默认为文档的根目录 | |
index | 是 | integer | 指定图片的索引 | |
destFilePath | 是 | string | 结果文档的存贮路径,如果省略该参数,则默认存到根目录 |
代码示例:
- .NET
- Java
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client;
namespace DeleteImage
{
class Program
{
static string appId = "your id";
static string appKey = "your key";
static string baseUrl = "https://api.e-iceblue.cn";
static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
static ImagesApi imagesApi = new ImagesApi(wordConfiguration);
static void Main(string[] args)
{
string name = "deleteImage.docx"; ;
string paragraphPath = "Section/0/Body/0/Paragraph/1";
int index = 0;
string folder = "input";
string storage = null;
string password = null;
string destFilePath = "output/addImage_out.docx";
imagesApi.DeleteImage(name, paragraphPath, index, destFilePath, folder, storage, password);
}
}
}
import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.ImagesApi;
public class DeleteImage {
static String appId = "your id";
static String appKey = "your key";
static String baseUrl = "https://api.e-iceblue.cn";
static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
static ImagesApi imagesApi = new ImagesApi(wordConfiguration);
public static void main(String[] args) throws ApiException {
String name = "deleteImage.docx";
String paragraphPath = "Section/0/Body/0/Paragraph/1";
Integer index = 0;
String folder = "input";
String storage = null;
String password = null;
String destFilePath = "output/addImage_out.docx";
imagesApi.deleteImage(name, paragraphPath, index, destFilePath, folder, storage, password);
}
}
接口方法 5:getImageFormat() 获取指定图片的参数
HTTP 请求方法:GET
请求 URL:https://api.e-iceblue.cn/v1/word/document/{name}/{paragraphPath}/images/{index}/format
请求参数:
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
name | 是 | string | 原文档名称 | |
folder | 否 | string | 存放原文档的文件夹,没有则为null | |
storage | 否 | string | 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null | |
password | 否 | string | 原文档密码,没有则为null | |
paragraphPath | 是 | string | 含有图片的段落路径,如果省略该参数,则默认为文档的根目录 | |
index | 是 | integer | 指定图片的索引 |
代码示例:
- .NET
- Java
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client;
namespace GetImageFormat
{
class Program
{
static string appId = "your id";
static string appKey = "your key";
static string baseUrl = "https://api.e-iceblue.cn";
static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
static ImagesApi imagesApi = new ImagesApi(wordConfiguration);
static void Main(string[] args)
{
string name = "getImageFormat.docx"; ;
string paragraphPath = "Section/0/Body/0/Paragraph/1";
int index = 0;
string folder = "input";
string storage = null;
string password = null;
imagesApi.GetImageFormat(name, paragraphPath, index, password, folder, storage);
}
}
}
import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.ImagesApi;
public class getImageFormat {
static String appId = "your id";
static String appKey = "your key";
static String baseUrl = "https://api.e-iceblue.cn";
static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
static ImagesApi imagesApi = new ImagesApi(wordConfiguration);
public static void main(String[] args) throws ApiException {
String name = "getImageFormat.docx";
String paragraphPath = "Section/0/Body/0/Paragraph/1";
Integer index = 0;
String folder = "input";
String storage = null;
String password = null;
imagesApi.getImageFormat(name, paragraphPath, index, password, folder, storage);
}
}
接口方法 6:updateImageFormat() 更新指定图片的参数
HTTP 请求方法:PUT
请求 URL:https://api.e-iceblue.cn/v1/word/document/{name}/{paragraphPath}/images/{index}/format
请求参数:
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
name | 是 | string | 原文档名称 | |
folder | 否 | string | 存放原文档的文件夹,没有则为null | |
storage | 否 | string | 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null | |
password | 否 | string | 原文档密码,没有则为null | |
paragraphPath | 是 | string | 含有图片的段落路径,如果省略该参数,则默认为文档的根目录 | |
index | 是 | integer | 指定图片的索引 | |
destFilePath | 是 | string | 结果文档的存贮路径,如果省略该参数,则默认存到根目录 | |
format | 是 | object | 图片参数对象 |
代码示例:
- .NET
- Java
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client;
using Spire.Cloud.Word.Sdk.Model;
namespace UpdateImageFormat
{
class Program
{
static string appId = "your id";
static string appKey = "your key";
static string baseUrl = "https://api.e-iceblue.cn";
static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
static ImagesApi imagesApi = new ImagesApi(wordConfiguration);
static void Main(string[] args)
{
string name = "updateImageFormat.docx";
string paragraphPath = "Section/0/Body/0/Paragraph/1";
int index = 0;
var format = new ImageFormat()
{
Width = 400,
Height = 400,
Rotation = 20,
VerticalPosition = 50,
HorizontalPosition = 50
};
string folder = "input";
string storage = null;
string password = null;
string destFilePath = "output/updateImageFormat_out.docx";
imagesApi.UpdateImageFormat(name, paragraphPath, index, destFilePath, format, password, folder, storage);
}
}
}
import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.ImagesApi;
import spire.cloud.word.sdk.client.model.ImageFormat;
public class UpdateImageFormat {
static String appId = "your id";
static String appKey = "your key";
static String baseUrl = "https://api.e-iceblue.cn";
static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
static ImagesApi imagesApi = new ImagesApi(wordConfiguration);
public static void main(String[] args) throws ApiException {
String name = "updateImageFormat.docx";
String paragraphPath = "Section/0/Body/0/Paragraph/1";
Integer index = 0;
ImageFormat format = new ImageFormat();
format.setWidth(400);
format.setHeight(400);
format.setRotation(20);
format.setVerticalPosition(50);
format.setHorizontalPosition(50);
String folder = "input";
String storage = null;
String password = null;
String destFilePath = "output/updateImageFormat_out.docx";
imagesApi.updateImageFormat(name, paragraphPath, index, destFilePath, format, password, folder, storage);
}
}