Getting Started
This article will get you started in using the RadSpreadStreamProcessing library. It contains the following sections:
If you still don't have Telerik Document Processing installed, check the First Steps topic to learn how you can obtain the packages through the different suites.
Assembly References
The libraries support .NET 4 and later. .NET Standard-compatible binaries are available as well. The assemblies for .NET Standard don't include 'Windows' in their names. (e.g. Telerik.Zip.dll).
In order to use RadSpreadStreamProcessing in your project, you will need to add the references listed below.
.NET Framework | .NET Standard-compatible |
---|---|
Telerik.Documents.SpreadsheetStreaming.dll | Telerik.Documents.SpreadsheetStreaming.dll |
Telerik.Windows.Zip.dll | Telerik.Zip.dll |
To describe different colors, shapes and other properties, RadSpreadStreamProcessing depends on the listed below .NET assemblies, which you should also refer in your project: | |
WindowsBase.dll | - |
PresentationFramework.dll | - |
The binaries compatible with .NET Standard are distributed with the packages targeting .NET Standard and .NET Core. For the full list of suites including Telerik Document Processing, check the Installing on Your Computer help topic. There are NuGet packages as well that you can access if you have a license for one of the above mentioned suites.
Create a Spreadsheet Document
This section will explain how a document could be created. If you need more detailed information about the classes that export the different document elements, you can check the articles from the Model section.
When creating a document with RadSpreadStreаmProcessing, the order in which the elements are created is very important. In order to minimize resource consumption, the library writes the content directly to a stream, and due to the structure of the file format, it is necessary to create the elements in the following order:
Create a Workbook
Create a Worksheet
Create Columns (optional)
Create Rows (a worksheet must contain at least one row)
Create Cells (optional)
Merge Cells (optional)
Example 1 shows how you could create a simple document.
Example 1: Create a document
using (FileStream stream = File.OpenWrite("sample.xlsx"))
{
using (IWorkbookExporter workbook = SpreadExporter.CreateWorkbookExporter(SpreadDocumentFormat.Xlsx, stream))
{
using (IWorksheetExporter worksheet = workbook.CreateWorksheetExporter("My sheet"))
{
worksheet.SkipColumns(1);
using (IColumnExporter column = worksheet.CreateColumnExporter())
{
column.SetWidthInPixels(80);
}
worksheet.SkipRows(3);
using (IRowExporter row = worksheet.CreateRowExporter())
{
row.SkipCells(3);
using (ICellExporter cell = row.CreateCellExporter())
{
cell.SetValue("Merged cell.");
cell.SetFormat(new SpreadCellFormat()
{
HorizontalAlignment = SpreadHorizontalAlignment.Center,
VerticalAlignment = SpreadVerticalAlignment.Center
});
}
}
using (IRowExporter row = worksheet.CreateRowExporter())
{
row.SetHeightInPixels(200);
using (ICellExporter cell = row.CreateCellExporter())
{
cell.SetValue(123.456);
}
using (ICellExporter cell = row.CreateCellExporter())
{
SpreadCellFormat format = new SpreadCellFormat()
{
NumberFormat = "dd/mm/yyyy",
IsBold = true
};
cell.SetFormat(format);
cell.SetValue(42370);
}
}
worksheet.MergeCells(3, 3, 6, 6);
}
}
}
Figure 1: The document created in Example 1
Read Existing Document
When reading a document with RadSpreadStreаmProcessing, the order of parsing the content is very important. To minimize resource consumption, the library parses only the parts required by the user and, due to the file structure, it is necessary to read the desired elements in the following order:
Read the Workbook
Read a Worksheet
Read Columns (optional)
Read Rows (a worksheet must contain at least one row)
Read Cells (optional)
Example 2 demonstrates how you could read the data from an existing document.
Example 2: Read data from a document
using (FileStream fs = new FileStream(fileName, FileMode.Open))
{
using (IWorkbookImporter workBookImporter = SpreadImporter.CreateWorkbookImporter(SpreadDocumentFormat.Xlsx, fs))
{
foreach (IWorksheetImporter worksheetImporter in workBookImporter.WorksheetImporters)
{
foreach (IRowImporter rowImporter in worksheetImporter.Rows)
{
foreach (ICellImporter cell in rowImporter.Cells)
{
string value = cell.Value;
}
}
}
}
}