操作 Excel 工作表中的指定区域内容,包括合并/拆分,复制,获取区域内容;设置区域格式,行高列宽等。
接口方法 1:copyRanges() 将 Excel 工作表中特定区域的内容复制到指定位置
HTTP 请求方法:POST
请求 URL:https://api.e-iceblue.cn/v1/excel /{name}/worksheets/{sheetName}/ranges
请求参数:
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
name | 是 | string | 文档名称 | |
sheetName | 是 | string | 指定工作表名称 | |
rangeOpeate | 是 | object | { "Target": { "RowHeight": 5, "ColumnCount": 0, "ColumnWidth": 6, "RefersTo": "RefersTo", "Worksheet": "Worksheet", "FirstColumn": 1, "FirstRow": 5, "RowCount": 5, "Name": "Name" }, "PasteOptions": { "SkipBlanks": true, "PasteType": "PasteType", "OnlyVisibleCells": true, "Transpose": true }, "Operate": "Operate", "Source": { "RowHeight": 5, "ColumnCount": 0, "ColumnWidth": 6, "RefersTo": "RefersTo", "Worksheet": "Worksheet", "FirstColumn": 1, "FirstRow": 5, "RowCount": 5, "Name": "Name" } } | 设置复制类型,如copydata, copystyle, copyto, copyvalue |
folder | 否 | string | 存放文档的文件夹,没有则为null | |
storage | 否 | string | 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null |
Java 代码示例:
import spire.cloud.excel.sdk.ApiException;
import spire.cloud.excel.sdk.Configuration;
import spire.cloud.excel.sdk.api.RangesApi;
import spire.cloud.excel.sdk.model.Range;
import spire.cloud.excel.sdk.model.RangeCopyRequest;
public class copyRanges {
static String appId = "your id";
static String appKey = "your key";
static String baseUrl = "https://api.e-iceblue.cn";
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
static RangesApi rangesApi = new RangesApi(configuration);
public static void main(String[] args) throws ApiException {
String name = "CopyRanges.xlsx";
String folder = "input";
String storage = null;
String sheetName = "Sheet1";
RangeCopyRequest rangeOperate = new RangeCopyRequest();
rangeOperate.setOperate("copystyle");
Range range = new Range();
range.firstColumn(1);
range.firstRow(1);
range.rowCount(10);
range.columnCount(10);
Range range2 = new Range();
range2.firstColumn(30);
range2.firstRow(1);
range2.rowCount(5);
range2.columnCount(8);
rangeOperate.source(range);
rangeOperate.target(range2);
rangesApi.copyRanges(name, sheetName, rangeOperate, folder, storage);
}
}
接口方法 2:mergeRange() 将 Excel 工作表中特定区域的数据合并到一个单元格
HTTP 请求方法:POST
请求 URL:https://api.e-iceblue.cn/v1/excel /{name}/worksheets/{sheetName}/ranges/merge
请求参数:
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
name | 是 | string | 文档名称 | |
sheetName | 是 | string | 指定工作表名称 | |
range | 是 | object | { "RowHeight": 5, "ColumnCount": 0, "ColumnWidth": 6, "RefersTo": "RefersTo", "Worksheet": "Worksheet", "FirstColumn": 1, "FirstRow": 5, "RowCount": 5, "Name": "Name" } | 指定合并的区域范围 |
folder | 否 | string | 存放文档的文件夹,没有则为null | |
storage | 否 | string | 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null |
Java 代码示例:
import spire.cloud.excel.sdk.ApiException;
import spire.cloud.excel.sdk.Configuration;
import spire.cloud.excel.sdk.api.RangesApi;
import spire.cloud.excel.sdk.model.Range;
public class mergeRange {
static String appId = "your id";
static String appKey = "your key";
static String baseUrl = "https://api.e-iceblue.cn";
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
static RangesApi rangesApi = new RangesApi(configuration);
public static void main(String[] args) throws ApiException {
String name = "MergeRange.xlsx";
String folder = "input";
String storage = null;
String sheetName = "Sheet1";
Range range = new Range();
range.firstColumn(3);
range.firstRow(3);
range.rowCount(5);
range.columnCount(8);
rangesApi.mergeRange(name, sheetName, range, folder, storage);
}
}
接口方法 3:unmergeRange() 取消合并 Excel 工作表中特定区域范围的数据
HTTP 请求方法:POST
请求 URL:https://api.e-iceblue.cn/v1/excel /{name}/worksheets/{sheetName}/ranges/unmerge
请求参数:
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
name | 是 | string | 文档名称 | |
sheetName | 是 | string | 指定工作表名称 | |
range | 是 | object | { "RowHeight": 5, "ColumnCount": 0, "ColumnWidth": 6, "RefersTo": "RefersTo", "Worksheet": "Worksheet", "FirstColumn": 1, "FirstRow": 5, "RowCount": 5, "Name": "Name" } | 指定合并的区域范围 |
folder | 否 | string | 存放文档的文件夹,没有则为null | |
storage | 否 | string | 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null |
Java 代码示例:
import spire.cloud.excel.sdk.ApiException;
import spire.cloud.excel.sdk.Configuration;
import spire.cloud.excel.sdk.api.RangesApi;
import spire.cloud.excel.sdk.model.Range;
public class unmergeRange {
static String appId = "your id";
static String appKey = "your key";
static String baseUrl = "https://api.e-iceblue.cn";
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
static RangesApi rangesApi = new RangesApi(configuration);
public static void main(String[] args) throws ApiException {
String name = "UnMergeRange.xlsx";
String folder = "input";
String storage = null;
String sheetName = "Sheet1";
Range range = new Range();
range.firstColumn(3);
range.firstRow(3);
range.rowCount(5);
range.columnCount(8);
rangesApi.unmergeRange(name, sheetName, range, folder, storage);
}
}
接口方法 4:setRangeStyle() 设置 Excel 工作表中特定区域的格式
HTTP 请求方法:POST
请求 URL:https://api.e-iceblue.cn/v1/excel /{name}/worksheets/{sheetName}/ranges/style
请求参数:
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
name | 是 | string | 文档名称 | |
sheetName | 是 | string | 指定工作表名称 | |
rangeOperate | 是 | object | { "Style": "", "Range": { "RowHeight": 5, "ColumnCount": 0, "ColumnWidth": 6, "RefersTo": "RefersTo", "Worksheet": "Worksheet", "FirstColumn": 1, "FirstRow": 5, "RowCount": 5, "Name": "Name" } } | 设置格式 |
folder | 否 | string | 存放文档的文件夹,没有则为null | |
storage | 否 | string | 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null |
Java 代码示例:
import spire.cloud.excel.sdk.ApiException;
import spire.cloud.excel.sdk.Configuration;
import spire.cloud.excel.sdk.api.RangesApi;
import spire.cloud.excel.sdk.model.*;
import java.util.ArrayList;
public class setRangeStyle {
static String appId = "your id";
static String appKey = "your key";
static String baseUrl = "https://api.e-iceblue.cn";
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
static RangesApi rangesApi = new RangesApi(configuration);
public static void main(String[] args) throws ApiException {
String name = "SetRangeStyle_1.xlsx";
String folder = "input";
String storage = null;
String sheetName = "Sheet1";
RangeSetStyleRequest rangeOperate = new RangeSetStyleRequest();
rangeOperate.setStyle(new Style());
rangeOperate.getStyle().font(new Font());
rangeOperate.getStyle().getFont().color(new Color(255, 255, 0, 0));
rangeOperate.getStyle().getFont().underline( "single");
rangeOperate.getStyle().getFont().size(12);
rangeOperate.getStyle().getFont().name("楷体");
rangeOperate.getStyle().getFont().isItalic(true);
rangeOperate.getStyle().getFont().isBold(true);
ArrayList<Border> lists = new ArrayList<Border>();
Border border = new Border();
border.setLineStyle("Medium");
border.setBorderType("EdgeTop");
border.setColor(new Color(255, 255, 0, 0));
lists.add(border);
Border border1 = new Border();
border1.setLineStyle("DashDot");
border1.setBorderType("EdgeRight");
border1.setColor(new Color(255, 0, 255, 0));
lists.add(border1);
Border border2 = new Border();
border2.setLineStyle("Thin");
border2.setBorderType("EdgeLeft");
border2.setColor(new Color(0, 160, 32, 240));
lists.add(border2);
rangeOperate.getStyle().setBorderCollection(lists);
rangeOperate.getStyle().horizontalAlignment("left");//需要设置HorizontalAlignment该属性方可生效
rangeOperate.getStyle().indentLevel(1);
rangeOperate.getStyle().textDirection("RightToLeft");
rangeOperate.getStyle().backgroundColor(new Color(0, 255, 255, 0));
rangeOperate.getStyle().isTextWrapped(true);
Range range = new Range();
range.firstColumn(2);
range.firstRow(1);
range.columnCount(1);
range.rowCount(10);
rangeOperate.range(range);
rangesApi.setRangeStyle(name, sheetName, rangeOperate, folder, storage);
}
}
接口方法 5:getRangeValue() 获取指定单元格区域的值
HTTP 请求方法:GET
请求 URL:https://api.e-iceblue.cn/v1/excel /{name}/worksheets/{sheetName}/ranges/value
请求参数:
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
name | 是 | string | 文档名称 | |
sheetName | 是 | string | 指定工作表名称 | |
namerange | 否 | string | 指定单元格区域 | |
firstRow | 否 | integer($int32) | 起始行 | |
firstColumn | 否 | integer($int32) | 起始列 | |
rowCount | 否 | integer($int32) | 总行数 | |
columnCount | 否 | integer($int32) | 总列数 | |
folder | 否 | string | 存放文档的文件夹,没有则为null | |
storage | 否 | string | 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null |
Java 代码示例:
import spire.cloud.excel.sdk.ApiException;
import spire.cloud.excel.sdk.Configuration;
import spire.cloud.excel.sdk.api.RangesApi;
import spire.cloud.excel.sdk.model.*;
public class getRangeValue {
static String appId = "your id";
static String appKey = "your key";
static String baseUrl = "https://api.e-iceblue.cn";
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
static RangesApi rangesApi = new RangesApi(configuration);
public static void main(String[] args) throws ApiException {
String name = "GetRangeValue.xlsx";
String sheetName = "Sheet1";
String folder = "input";
String storage = null;
String nameRange = "C1:D3";
RangeValue response = rangesApi.getRangeValue(name, sheetName, nameRange, null, null, null, null, folder, storage);
}
}
接口方法 6:setRangeValue() 设置 Excel 工作表中特定单元格区域的值
HTTP 请求方法:POST
请求 URL:https://api.e-iceblue.cn/v1/excel /{name}/worksheets/{sheetName}/ranges/value
请求参数:
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
name | 是 | string | 文档名称 | |
sheetName | 是 | string | 指定工作表名称 | |
range | 是 | object | { "RowHeight": 5, "ColumnCount": 0, "ColumnWidth": 6, "RefersTo": "RefersTo", "Worksheet": "Worksheet", "FirstColumn": 1, "FirstRow": 5, "RowCount": 5, "Name": "Name" } | 指定单元格区域范围 |
value | 是 | string | 输入值 | |
isConverted | 否 | boolean | 判断是否转换成其他数据类型,默认为false | |
setStyle | 否 | boolean | 判断数字类型是否会重置,默认为false | |
folder | 否 | string | 存放文档的文件夹,没有则为null | |
storage | 否 | string | 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null |
Java 代码示例:
import spire.cloud.excel.sdk.ApiException;
import spire.cloud.excel.sdk.Configuration;
import spire.cloud.excel.sdk.api.RangesApi;
import spire.cloud.excel.sdk.model.*;
public class setRangeValue {
static String appId = "your id";
static String appKey = "your key";
static String baseUrl = "https://api.e-iceblue.cn";
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
static RangesApi rangesApi = new RangesApi(configuration);
public static void main(String[] args) throws ApiException {
String name = "SetRangeValue.xlsx";
String folder = "input";
String storage = null;
String sheetName = "Sheet2";
Range range = new Range();
range.firstRow(1);
range.firstColumn(1);
range.columnCount(5);
range.rowCount(2);
String value = "E-iceblue";
boolean isConverted = true;
boolean setStyle = false;
rangesApi.setRangeValue(name, sheetName, range, value, isConverted, setStyle, folder, storage);
}
}
接口方法 7:moveRange() 将 Excel 工作表中特定单元格区域移动到其他指定位置
HTTP 请求方法:POST
请求 URL:https://api.e-iceblue.cn/v1/excel /{name}/worksheets/{sheetName}/ranges/moveto
请求参数:
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
name | 是 | string | 文档名称 | |
sheetName | 是 | string | 指定工作表名称 | |
range | 是 | object | { "RowHeight": 5, "ColumnCount": 0, "ColumnWidth": 6, "RefersTo": "RefersTo", "Worksheet": "Worksheet", "FirstColumn": 1, "FirstRow": 5, "RowCount": 5, "Name": "Name" } | 指定单元格区域范围 |
value | 是 | string | 输入值 | |
isConverted | 否 | boolean | 判断是否转换成其他数据类型,默认为false | |
setStyle | 否 | boolean | 判断数字类型是否会重置,默认为false | |
folder | 否 | string | 存放文档的文件夹,没有则为null | |
storage | 否 | string | 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null |
Java 代码示例:
import spire.cloud.excel.sdk.ApiException;
import spire.cloud.excel.sdk.Configuration;
import spire.cloud.excel.sdk.api.RangesApi;
import spire.cloud.excel.sdk.model.*;
public class moveRange {
static String appId = "your id";
static String appKey = "your key";
static String baseUrl = "https://api.e-iceblue.cn";
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
static RangesApi rangesApi = new RangesApi(configuration);
public static void main(String[] args) throws ApiException {
String name = "MoveRange.xlsx";
String folder = "input";
String storage = null;
String sheetName = "Sheet1";
Range range = new Range();
range.firstColumn(1);
range.firstRow(1);
range.rowCount(1);
range.columnCount(1);
int destRow = 25;
int destColumn = 3;
rangesApi.moveRange(name, sheetName, range, destRow, destColumn, folder, storage);
}
}
接口方法 8:setRangeOutlineBorder() 设置单元格区域的外边框
HTTP 请求方法:POST
请求 URL:https://api.e-iceblue.cn/v1/excel /{name}/worksheets/{sheetName}/ranges/outlineBorder
请求参数:
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
name | 是 | string | 文档名称 | |
sheetName | 是 | string | 指定工作表名称 | |
rangeOpeare | 是 | object | { "borderColor": { "A": 0, "R": 6, "B": 5, "G": 1 }, "borderEdge": "borderEdge", "Range": { "RowHeight": 5, "ColumnCount": 0, "ColumnWidth": 6, "RefersTo": "RefersTo", "Worksheet": "Worksheet", "FirstColumn": 1, "FirstRow": 5, "RowCount": 5, "Name": "Name" }, "borderStyle": "borderStyle" } | 设置单元格区域外边框样式 |
folder | 否 | string | 存放文档的文件夹,没有则为null | |
storage | 否 | string | 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null |
Java 代码示例:
import spire.cloud.excel.sdk.ApiException;
import spire.cloud.excel.sdk.Configuration;
import spire.cloud.excel.sdk.api.RangesApi;
import spire.cloud.excel.sdk.model.*;
public class setRangeOutlineBorder {
static String appId = "your id";
static String appKey = "your key";
static String baseUrl = "https://api.e-iceblue.cn";
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
static RangesApi rangesApi = new RangesApi(configuration);
public static void main(String[] args) throws ApiException {
String name = "SetRangeOutlineBorder.xlsx";
String folder = "input";
String storage = null;
String sheetName = "Sheet1";
RangeSetOutlineBorderRequest rangeOperate =
new RangeSetOutlineBorderRequest();
rangeOperate.borderEdge("outline");//Available value: vertical, horizontal, outline, edgeleft and so on.
rangeOperate.borderStyle("Medium");//Available value: Medium, DashDot, Thin, Dotted, Hair, MediumDashDot, MediumDashDotDot and so on.
rangeOperate.borderColor(new Color(255, 255, 0, 0));
Range range = new Range();
range.firstColumn(1);
range.firstRow(1);
range.columnCount(10);
range.rowCount(5);
rangeOperate.range(range);
rangesApi.setRangeOutlineBorder(name, sheetName, rangeOperate, folder, storage);
}
}
接口方法 9:setRangeColumnWidth() 设置特定单元格区域中的列宽
HTTP 请求方法:POST
请求 URL:https://api.e-iceblue.cn/v1/excel /{name}/worksheets/{sheetName}/ranges/columnWidth
请求参数:
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
name | 是 | string | 文档名称 | |
sheetName | 是 | string | 指定工作表名称 | |
range | 是 | object | { "RowHeight": 5, "ColumnCount": 0, "ColumnWidth": 6, "RefersTo": "RefersTo", "Worksheet": "Worksheet", "FirstColumn": 1, "FirstRow": 5, "RowCount": 5, "Name": "Name" } | 指定单元格区域范围 |
value | 是 | number($double) | 设置列的宽度 | |
folder | 否 | string | 存放文档的文件夹,没有则为null | |
storage | 否 | string | 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null |
Java 代码示例:
import spire.cloud.excel.sdk.ApiException;
import spire.cloud.excel.sdk.Configuration;
import spire.cloud.excel.sdk.api.RangesApi;
import spire.cloud.excel.sdk.model.*;
public class setRangeColumnWidth {
static String appId = "your id";
static String appKey = "your key";
static String baseUrl = "https://api.e-iceblue.cn";
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
static RangesApi rangesApi = new RangesApi(configuration);
public static void main(String[] args) throws ApiException {
String name = "SetRangeColumnWidth.xlsx";
String folder = "input";
String storage = null;
String sheetName = "Sheet1";
Range range = new Range();
range.firstColumn(1);
range.firstRow(1);
range.rowCount(2);
range.columnCount(5);
double value = 15;
rangesApi.setRangeColumnWidth(name, sheetName, range, value, folder, storage);
}
}
接口方法 10:setRangeRowHeight() 设置特定单元格区域中的行高
HTTP 请求方法:POST
请求 URL:https://api.e-iceblue.cn/v1/excel /{name}/worksheets/{sheetName}/ranges/rowHeight
请求参数:
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
name | 是 | string | 文档名称 | |
sheetName | 是 | string | 指定工作表名称 | |
range | 是 | object | { "RowHeight": 5, "ColumnCount": 0, "ColumnWidth": 6, "RefersTo": "RefersTo", "Worksheet": "Worksheet", "FirstColumn": 1, "FirstRow": 5, "RowCount": 5, "Name": "Name" } | 指定单元格区域范围 |
value | 是 | number($double) | 设置行的高度 | |
folder | 否 | string | 存放文档的文件夹,没有则为null | |
storage | 否 | string | 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null |
Java 代码示例:
import spire.cloud.excel.sdk.ApiException;
import spire.cloud.excel.sdk.Configuration;
import spire.cloud.excel.sdk.api.RangesApi;
import spire.cloud.excel.sdk.model.*;
public class setRangeRowHeight {
static String appId = "your id";
static String appKey = "your key";
static String baseUrl = "https://api.e-iceblue.cn";
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
static RangesApi rangesApi = new RangesApi(configuration);
public static void main(String[] args) throws ApiException {
String name = "SetRangeRowHeight.xlsx";
String folder = "input";
String storage = null;
String sheetName = "Sheet1";
Range range = new Range();
range.firstColumn(1);
range.firstRow(1);
range.columnCount(5);
range.rowCount(10);
double value = 20;
rangesApi.setRangeRowHeight(name, sheetName, range, value, folder, storage);
}
}