Spire.Cloud.Excel provides the WorksheetsApi interface to manipulate worksheets in an Excel document. This article will demonstrate how to freeze or unfreeze rows and columns by using this interface.
Example 1: Freeze rows and columns
import spire.cloud.excel.sdk.*;
import spire.cloud.excel.sdk.api.WorksheetsApi;
public class FreezeRowsAndColumns{
static String appId = "App ID";
static String appKey = "App Key";
static String baseUrl = "https://api.cloudxdocs.com";
public static void main(String[] args) throws ApiException {
// Create a Configuration object based on your App ID and App Key
Configuration configuration = new Configuration(appId, appKey, baseUrl);
//Initialize a WorksheetsApi object
WorksheetsApi WorksheetsApi = new WorksheetsApi(configuration);
//Load an Excel sample
String name = "Sample.xlsx";
//Specify the folder storing the sample, it’s null if nothing
String folder = "input";
//Use the 2G storage provided by E-iceblue Cloud, it’s null by default
String storage = null;
//Specify the worksheet to be frozen
String sheetName = "Country List";
//Specify the row to be frozen
int freezedRows = 3;
//Specify the column to be frozen
int freezedColumns = 3;
//Call the setFreezePanes method to freeze the specified row and column in the Excel worksheet
WorksheetsApi.setFreezePanes(name, sheetName, freezedRows, freezedColumns, folder, storage);
}
}
Example 2: Unfreeze rows and columns
import spire.cloud.excel.sdk.*;
import spire.cloud.excel.sdk.api.WorksheetsApi;
public class UnfreezeRowsAndColumns {
static String appId = "App ID";
static String appKey = "App Key";
static String baseUrl = "https://api.cloudxdocs.com";
public static void main(String[] args) throws ApiException {
//Create a Configuration object based on your App ID and App Key
Configuration configuration = new Configuration(appId, appKey, baseUrl);
//Initialize a WorksheetsApi object
WorksheetsApi WorksheetsApi = new WorksheetsApi(configuration);
//Load an Excel sample
String name = "Sample.xlsx";
//Specify the folder storing the sample, it’s null if nothing
String folder = "input";
//Use the 2G storage provided by E-iceblue Cloud, it’s null by default
String storage = null;
//Specify the worksheet to be unfrozen
String sheetName = "Country List";
//Call the deleteFreezePanes method to unfreeze the frozen row and column in the Excel worksheet
WorksheetsApi.deleteFreezePanes(name, sheetName, folder, storage);
}
}