Java 合并/拆分Excel单元格
1、下载地霸脾购址:E-iceblue中文官网-在线编辑泛牺-下载中心
下载后,创建Maven项目程序,并颂诉在pom.xml文件中配置 Maven 仓库路径,指定 spire.cloud.sdk的 Maven 依赖,导入程序需要的所有jar文件。如下导入结果:

1、方法参考如下图中的步骤:

1、程序使用的文档路径是“文档管理”目录下的文件夹路径,冰蓝云提供的2G的免费存储空间。

1、import spire.cloud.excel.sdk.Configuration;
import spire.cloud.excel.sdk.api.CellsApi;
public class MergeCells {
//配置App ID和App Key等应用账号信息
static String appId = "App ID";
static String appKey = "App Key";
static String baseUrl = "https://api.e-iceblue.cn";
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
static CellsApi cellsApi = new CellsApi(configuration);
public static void main(String[] args) throws Exception {
String name = "test.xlsx";//Excel测试文档
String folder = "input";//Excel文档所在的云端文件夹
String storage = null;//使用冰蓝云配置的2G存储空间,可设置为null
String sheetName = "Sheet2";//指定Excel中的工作表
//指定合并的起始行和列,并指定需要合并的行数和列数
int startRow = 1;
int startColumn = 2;
int totalRows = 4;
int totalColumns = 3;
//调用接口提供的方法合并单元格(运行程序后,可在云端的源文档中查看单元格合并效果)
cellsApi.mergeCells(name, sheetName, startRow, startColumn, totalRows, totalColumns, folder, storage);
}
}
2、单元格合并前/后效果:
合并前

3、合并后:

1、import spire.cloud.excel.sdk.Configuration;
import spire.cloud.excel.sdk.api.CellsApi;
public class UnmergeCell {
//配置App ID和App Key等应用账号信息
static String appId = "App ID";
static String appKey = "App Key";
static String baseUrl = "https://api.e-iceblue.cn";
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
static CellsApi cellsApi = new CellsApi(configuration);
public static void main(String[] args) throws Exception{
String name = "test.xlsx";//Excel测试文档
String folder = "input";//Excel文档所在的云端文件夹
String storage = null;//使用冰蓝云配置的2G存储空间,可设置为null
String sheetName = "Sheet3";//指定Excel中的工作表
int startRow = 3;
int startColumn = 3;
int totalRows = 1;
int totalColumns =1;
//调用方法拆分单元格(运行程序后,可在云端的源文档中查看单元格拆分效果)
cellsApi.unmergeCells(name, sheetName, startRow, startColumn, totalRows, totalColumns, folder, storage);
}
}
2、拆分结果:
拆分前

3、拆分后

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:191
阅读量:169
阅读量:162
阅读量:66
阅读量:159