This module uses the DevExpress Spreadsheet API to freeze panes in an Excel document. You can process the predefined sample file or supply your own document. To do the latter, select Upload a File in the file selection drop-down menu.
Set the number of rows and columns to freeze. To freeze columns only, set the number of rows to 0 (and vice versa).
Use the Freeze Panes and Save as XLSX dropdown button to select the output format, run the operation, and download the result.
Select a Document
InvestmentPortfolio.xlsx
using DevExpress.Spreadsheet;
async Task<Stream> FreezePanes(Stream inputStream, int rowOffset, int columnOffset, DocumentFormat outputFormat) {
using Workbook workbook = new Workbook();
var firstWorksheet = workbook.Worksheets.First();
// Freeze Panes
if(rowOffset > 0 && columnOffset > 0) {
// Freeze both rows and columns
firstWorksheet.FreezePanes(rowOffset - 1, columnOffset - 1);
} else {
if(rowOffset == 0) {
// Freeze columns only
firstWorksheet.FreezeColumns(columnOffset - 1);
}
if(columnOffset == 0) {
// Freeze rows only
firstWorksheet.FreezeRows(rowOffset - 1);
}
}
// Prepare output stream
var outputStream = new MemoryStream();
// Save the resulting document
await workbook.SaveDocumentAsync(outputStream, outputFormat);
outputStream.Seek(0, SeekOrigin.Begin);
return outputStream;
}