操作Word文档中的文本区域,包括获取指定段落中的文本区域,添加文本区域到指定段落,获取文字区域的字符样式等。
接口方法1:getTextRanges()获取文字区域
HTTP请求方法:GET
请求URL:https://api.e-iceblue.cn/v1/word/document/{name}/{paragraphPath}/textRanges
请求参数:
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
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 textRangesApi
{
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 TextRangesApi textRangesApi = new TextRangesApi(wordConfiguration);
static void Main(string[] args)
{
string name = "Template.docx";
string paragraphPath = "Section/0/Body/0/Paragraph/0";
string folder = "input";
string storage = null;
string password = null;
var response = textRangesApi.GetTextRanges(name, paragraphPath, folder, storage, password);
}
}
}
import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.TextRangesApi;
import spire.cloud.word.sdk.client.model.*;
import java.util.List;
public class GetTextRanges {
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 TextRangesApi textRangesApi = new TextRangesApi(wordConfiguration);
public static void main(String[] args) throws ApiException {
String name = "Template.docx";
String paragraphPath = "Section/0/Body/0/Paragraph/0";
String folder = "input";
String storage = null;
String password = null;
List<ObjectInfo> response = textRangesApi.getTextRanges(name, paragraphPath, folder, storage, password);
}
}
接口方法2: addTextRange()添加文字区域
HTTP请求方法:POST
请求URL:https://api.e-iceblue.cn/v1/word/document/{name}/{paragraphPath}/textRanges
请求参数:
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
name | 是 | string | 原文档名称 | |
folder | 否 | string | 存放原文档的文件夹,没有则为null | |
storage | 否 | string | 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null | |
password | 否 | string | 原文档密码,没有则为null | |
paragraphPath | 是 | string | 指定段落的路径 | |
indexInParagraph | 否 | integer | 段落中插入文字区域的位置 | |
text | 是 | string | 文字区域的文字 | |
destFilePath | 是 | string | 结果文档的存贮路径,如果省略该参数,则默认存到根目录 |
代码示例:
- .NET
- Java
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client;
namespace AddTextRange
{
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 TextRangesApi textRangesApi = new TextRangesApi(wordConfiguration);
static void Main(string[] args)
{
string name = "Template.docx";
string paragraphPath = "Section/0/Body/0/Paragraph/0";
int? indexInParagraph = 0;
string text = "E-iceblue";
string folder = "input";
string storage = null;
string password = null;
string destFilePath = "output/AddTextRange_output.docx";
textRangesApi.AddTextRange(name, paragraphPath, text, destFilePath, folder, storage, indexInParagraph, password);
}
}
}
import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.TextRangesApi;
public class AddTextRange {
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 TextRangesApi textRangesApi = new TextRangesApi(wordConfiguration);
public static void main(String[] args) throws ApiException {
String name = "Template.docx";
String paragraphPath = "Section/0/Body/0/Paragraph/0";
Integer indexInParagraph = 0;
String text = "E-iceblue";
String folder = "input";
String storage = null;
String password = null;
String destFilePath = "output/AddTextRange_output.docx";
textRangesApi.addTextRange(name, paragraphPath, text, destFilePath, folder, storage, indexInParagraph, password);
}
}
接口方法3: getTextRangeFormat()获取文字区域的字符样式
HTTP请求方法:GET
请求URL:https://api.e-iceblue.cn/v1/word /document/{name}/{paragraphPath}/textRanges/{index}/characterFormat
请求参数:
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
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 GetTextRangeFormat
{
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 TextRangesApi textRangesApi = new TextRangesApi(wordConfiguration);
static void Main(string[] args)
{
string name = "getTextRangeFormat.docx";
string paragraphPath = "Section/0/Body/0/Paragraph/0";
int? index = 0;
string folder = "input";
string storage = null;
string password = null;
var response = textRangesApi.GetTextRangeFormat(name, paragraphPath, index, folder, storage, password);
}
}
}
import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.TextRangesApi;
import spire.cloud.word.sdk.client.model.TextRangeFormat;
public class GetTextRangeFormat {
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 TextRangesApi textRangesApi = new TextRangesApi(wordConfiguration);
public static void main(String[] args) throws ApiException {
String name = "getTextRangeFormat.docx";
String paragraphPath = "Section/0/Body/0/Paragraph/0";
Integer index = 0;
String folder = "input";
String storage = null;
String password = null;
TextRangeFormat response = textRangesApi.getTextRangeFormat(name, paragraphPath, index, folder, storage, password);
}
}
接口方法4:updateTextRangeFormat()更新文字区域的字符样式
HTTP请求方法:PUT
请求URL:https://api.e-iceblue.cn/v1/word/document/{name}/{paragraphPath}/textRanges/{index}/characterFormat
请求参数:
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
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;
using Spire.Cloud.Word.Sdk.Model;
namespace UpdateTextRangeFormat
{
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 TextRangesApi textRangesApi = new TextRangesApi(wordConfiguration);
static void Main(string[] args)
{
string name = "Template.docx";
string paragraphPath = "Section/0/Body/0/Paragraph/0";
int index = 0;
TextRangeFormat textRange = new TextRangeFormat
{
Font = new Font(30, "Arial")
{
Color = new Color(0, 255, 255)
}
};
string folder = "input";
string storage = null;
string password = null;
string destFilePath = "output/UpdateTextRangeFormat_output.docx";
textRangesApi.UpdateTextRangeFormat(name, paragraphPath, index, textRange, destFilePath, folder, storage, password);
}
}
}
import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.TextRangesApi;
import spire.cloud.word.sdk.client.model.*;
public class UpdateTextRangeFormat {
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 TextRangesApi textRangesApi = new TextRangesApi(wordConfiguration);
public static void main(String[] args) throws ApiException {
String name = "Template.docx";
String paragraphPath = "Section/0/Body/0/Paragraph/0";
Integer index = 0;
TextRangeFormat format = new TextRangeFormat();
Color color = new Color(0, 255, 255);
Font font = new Font("ו", 30f, color);
format.setFont(font);
TextRangeFormat textRange = format;
String folder = "input";
String storage = null;
String password = null;
String destFilePath = "output/UpdateTextRangeFormat_output.docx";
textRangesApi.updateTextRangeFormat(name, paragraphPath, index, textRange, destFilePath, folder, storage, password);
}
}
接口方法5:getTextRangeText()获取文字区域的文字
HTTP请求方法:GET
请求URL:https://api.e-iceblue.cn/v1/word/document/{name}/{paragraphPath}/textRanges/{index}/text
请求参数:
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
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 GetTextRangeText
{
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 TextRangesApi textRangesApi = new TextRangesApi(wordConfiguration);
static void Main(string[] args)
{
string name = "Template.docx";
string paragraphPath = "Section/0/Body/0/Paragraph/0";
int index = 0;
string folder = "input";
string storage = null;
string password = null;
var response = textRangesApi.GetTextRangeText(name, paragraphPath, index, folder, storage, password);
}
}
}
import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.TextRangesApi;
public class GetTextRangeText {
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 TextRangesApi textRangesApi = new TextRangesApi(wordConfiguration);
public static void main(String[] args) throws ApiException {
String name = "Template.docx";
String paragraphPath = "Section/0/Body/0/Paragraph/0";
Integer index = 0;
String folder = "input";
String storage = null;
String password = null;
String response = textRangesApi.getTextRangeText(name, paragraphPath, index, folder, storage, password);
}
}
接口方法6:updateTextRangeText()更新文字区域的文字
HTTP请求方法:PUT
请求URL:https://api.e-iceblue.cn/v1/word/document/{name}/{paragraphPath}/textRanges/{index}/text
请求参数:
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
name | 是 | string | 原文档名称 | |
folder | 否 | string | 存放原文档的文件夹,没有则为null | |
storage | 否 | string | 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null | |
password | 否 | string | 原文档密码,没有则为null | |
paragraphPath | 是 | string | 指定段落的路径 | |
index | 是 | integer | 文字区域的索引 | |
text | 是 | string | 文字区域的文字 | |
destFilePath | 是 | string | 结果文档的存贮路径,如果省略该参数,则默认存到根目录 |
代码示例:
- .NET
- Java
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client;
namespace UpdateTextRangeText
{
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 TextRangesApi textRangesApi = new TextRangesApi(wordConfiguration);
static void Main(string[] args)
{
string name = "Template.docx";
string paragraphPath = "Section/0/Body/0/Paragraph/0"; ;
int index = 0;
string text = "E-iceblue test textRange";
string folder = "input";
string storage = null;
string password = null;
string destFilePath = "output/UpdateTextRangeText_output.docx";
var response = textRangesApi.UpdateTextRangeText(name, paragraphPath, index, text, destFilePath, folder, storage, password);
}
}
}
import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.TextRangesApi;
public class UpdateTextRangeText {
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 TextRangesApi textRangesApi = new TextRangesApi(wordConfiguration);
public static void main(String[] args) throws ApiException {
String name = "Template.docx";
String paragraphPath = "Section/0/Body/0/Paragraph/0"; ;
Integer index = 0;
String text = "E-iceblue test textRange";
String folder = "input";
String storage = null;
String password = null;
String destFilePath = "output/UpdateTextRangeText_output.docx";
String response = textRangesApi.updateTextRangeText(name, paragraphPath, index, text, destFilePath, folder, storage, password);
}
}
接口方法7:deleteTextRange()删除文字区域
HTTP请求方法:DELETE
请求URL:https://api.e-iceblue.cn/v1/word/document/{name}/{paragraphPath}/textRanges/{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 DeleteTextRange
{
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 TextRangesApi textRangesApi = new TextRangesApi(wordConfiguration);
static void Main(string[] args)
{
string name = "deleteTextRange.docx";
string paragraphPath = "Section/0/Body/0/Paragraph/0";
int? index = 0;
string folder = "input";
string storage = null;
string password = null;
string destFilePath = "output/DeleteTextRange_output.docx";
textRangesApi.DeleteTextRange(name, paragraphPath, index, destFilePath, folder, storage, password);
}
}
}
import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.TextRangesApi;
public class AddParagraph {
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 TextRangesApi textRangesApi = new TextRangesApi(wordConfiguration);
public static void main(String[] args) throws ApiException {
String name = "deleteTextRange.docx";
String paragraphPath = "Section/0/Body/0/Paragraph/0";
Integer index = 0;
String folder = "input";
String storage = null;
String password = null;
String destFilePath = "output/DeleteTextRange_output.docx";
textRangesApi.deleteTextRange(name, paragraphPath, index, destFilePath,folder, storage, password);
}
}