This article demonstrates how to merge and unmerge cells using the RangesApi interface provided by Spire.Cloud.Excel.
Merge cells
using Spire.Cloud.Excel.Sdk.Api;
using Spire.Cloud.Excel.Sdk.Client;
using Spire.Cloud.Excel.Sdk.Model;
using System;
namespace MergeCells
{
class Program
{
static String appId = "APP ID";
static String appKey = "APP Key";
static String baseUrl = "https://api.cloudxdocs.com";
//Create a Configuration instance based on your AppID and AppKey
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
//Create a RangesApi instance
static RangesApi rangesApi = new RangesApi(configuration);
static void Main(string[] args)
{
//Specify the input document
string name = "sample.xlsx";
//Specify the folder storing the input document, and it's "null" if nothing
string folder = "input";
//Use the 2G storage provided by E-iceblue, and it's "null" by default
string storage = null;
//Specify the worksheet name
string sheetName = "Sheet1";
//Specify the cell range you want to merge
Range range = new Range();
range.FirstRow = 5;
range.FirstColumn = 2;
range.RowCount = 3;
range.ColumnCount = 1;
//Call MergeRange method to merge cells in the document
rangesApi.MergeRange(name, sheetName, range, folder, storage);
}
}
}
Output
Unmerge cells
using Spire.Cloud.Excel.Sdk.Api;
using Spire.Cloud.Excel.Sdk.Client;
using Spire.Cloud.Excel.Sdk.Model;
using System;
namespace UnmergeCells
{
class Program
{
static String appId = "APP ID";
static String appKey = "APP Key";
static String baseUrl = "https://api.cloudxdocs.com";
//Create a Configuration instance based on your AppID and AppKey
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
//Create a RangesApi instance
static RangesApi rangesApi = new RangesApi(configuration);
static void Main(string[] args)
{
//Specify the input document
string name = "sample.xlsx";
//Specify the folder storing the input document, and it's "null" if nothing
string folder = "input";
//Use the 2G storage provided by E-iceblue, and it's "null" by default
string storage = null;
//Specify the worksheet name
string sheetName = "Sheet1";
//Specify the cell range you want to merge
Range range = new Range();
range.FirstRow = 5;
range.FirstColumn = 2;
range.RowCount = 3;
range.ColumnCount = 1;
//Call UnMergeRange method to unmerge cells in the document
rangesApi.UnMergeRange(name, sheetName, range, folder, storage);
}
}
}
Output