Spire.Cloud.Excel provides the WorksheetsApi interface to handle worksheets in an Excel document. This article shows you how to freeze or unfreeze columns and rows by using this API.
Example 1. Freeze columns and rows
using System;
using Spire.Cloud.Excel.Sdk.Api;
using Spire.Cloud.Excel.Sdk.Client;
namespace FreezePanes
{
class Program
{
static String appId = "App ID";
static String appKey = "App Key";
static String baseUrl = "https://api.cloudxdocs.com";
//Create a Configuration object based on App ID and App Key
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
//Create a WorksheetsApi object
static WorksheetsApi WorksheetsApi = new WorksheetsApi(configuration);
static void Main(string[] args)
{
//Specify the source document name
string name = "sample-2.xlsx";
//Specify the folder where the source document is stored
string folder = "input";
//Use the default storage, set to null
string storage = null;
//Specify the worksheet name
string sheetName = "vendors";
//Specify the index of the row to be freezed
int? freezedRows = 3;
//Specify the index of the column to be freezed
int? freezedColumns = 3;
//Call SetFreezePanes to freeze the specified row and column
WorksheetsApi.SetFreezePanes(name, sheetName, freezedRows, freezedColumns, folder, storage);
}
}
}
Example 2. Unfreeze columns and rows
using System;
using Spire.Cloud.Excel.Sdk.Api;
using Spire.Cloud.Excel.Sdk.Client;
namespace UnfreezePanes
{
class Program
{
static String appId = "App ID";
static String appKey = " App Key";
static String baseUrl = "https://api.cloudxdocs.com";
//Create a Configureation object based on App ID and App Key
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
//Create a WorksheetsApi object
static WorksheetsApi WorksheetsApi = new WorksheetsApi(configuration);
static void Main(string[] args)
{
//Specify the source document name
string name = "sample-2.xlsx";
//Specify the folder where the source document is stored
string folder = "input";
//Use the default storage, set to null
string storage = null;
//Specify the worksheet name
string sheetName = "vendors";
//Call DeleteFreezePanes method to unfreeze columns and rows
WorksheetsApi.DeleteFreezePanes(name, sheetName, folder, storage);
}
}
}