The Workbook.FromDocument() method freezes the panes based on the coordinates of the TopLeftCellIndex of the pane instead of the XSplit and YSplit properties of the pane. Reproduced with the attached Excel file
var pane = documentWorksheet.ViewState.Pane;
if (pane != null && pane.State == PaneState.Frozen)
{
sheet.FrozenRows = pane.TopLeftCellIndex.RowIndex;
sheet.FrozenColumns = pane.TopLeftCellIndex.ColumnIndex;
}
Solution:
var pane = documentWorksheet.ViewState.Pane;
if (pane != null && pane.State == PaneState.Frozen)
{
sheet.FrozenRows = pane.YSplit;
sheet.FrozenColumns = pane.XSplit;
}
WORKAROUND: Loading the Excel file with DocumentProcessingLibrary API and change the pane
var fileName = <YourFilePathHere...>;
if (!File.Exists(fileName))
{
throw new FileNotFoundException(String.Format("File {0} was not found!", fileName));
}
Telerik.Windows.Documents.Spreadsheet.Model.Workbook workbook;
IWorkbookFormatProvider formatProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider();
using (Stream input = new FileStream(fileName, FileMode.Open))
{
workbook = formatProvider.Import(input);
foreach (var sheet in workbook.Worksheets)
{
if (sheet.ViewState.Pane != null && sheet.ViewState.Pane.State == Telerik.Windows.Documents.Spreadsheet.Model.PaneState.Frozen)
{
var originalPane = sheet.ViewState.Pane;
var pane = new Pane(new CellIndex(originalPane.YSplit, originalPane.XSplit), originalPane.XSplit, originalPane.YSplit, originalPane.ActivePane);
sheet.ViewState.Pane = pane;
}
}
}
var sheets = Telerik.Web.Spreadsheet.Workbook.FromDocument(workbook).Sheets;