New to Telerik UI for ASP.NET Core? Download free 30-day trial

Understanding Telerik.Web.Spreadsheet and Document Processing Library Spreadsheet Workbook and Worksheets

Description

I have implemented a Spreadsheet Server Export however I need to convert the exported Workbook to be usable with your Document Processing Library so I can modify it further. How can I achieve this?

Differences

The assemblies from the Telerik.Web.Spreadsheet(later referred as Core) suite and Document Processing Library(later referred as DPL) both have Workbook and Worksheet classes which have different capabilities.

Converting from One to the Other

The Workbook and worksheets from the Core and DPL are not interchangeable. Nevertheless, the Core Workbook class has some methods that allow converting from one to another and vice-versa:

  • An instance method .ToDocument() that all allows any Core Workbook instance to be converted to a DPL Workbook;
  • A static method Workbook.FromDocument() that allows any DPL Workbook to be converted to a Core Workbook;
using System;
using DPL = Telerik.Windows.Documents.Spreadsheet.Model;
using Core = Telerik.Web.Spreadsheet;
using System.Collections.Generic;
// Core to Document Processing Library
Core.Workbook CoreWorkbook = new Core.Workbook();
Core.Worksheet CoreWorksheet = CoreWorkbook.AddSheet();

Core.Row row = new Core.Row() { Index = 2, Cells = new List<Core.Cell> { } };
row.AddCell(new Core.Cell() { Index = 2, Value = "Test cell" });
CoreWorksheet.AddRow(row);

DPL.Workbook dplWorkbook = CoreWorkbook.ToDocument();
DPL.Sheet dplSheet = dplWorkbook.Sheets[0];
DPL.Worksheet dplWorksheet =  dplWorkbook.Worksheets[0];

// Document Processing Library to Core
Core.Workbook convertedCoreWorkbook = Core.Workbook.FromDocument(dplWorkbook);
Core.Worksheet convertedCoreWorksheet = convertedCoreWorkbook.Sheets[0];

// value is "Test cell"
string value = convertedCoreWorksheet
    .Rows.Find(r=> r.Index == 2)
    .Cells.Find(c=> c.Index == 2)
    .Value.ToString();

More ASP.NET Core Spreadsheet Resources

See Also

In this article