Rows
This article will help you get familiar with the concept of a row and its features.
What is a Row
Rows in the terms of a spreadsheet document are groups of cells that are on the same horizontal line. Each row is identified by a number. For example, the first row has an index 1, the second one – 2 and the last one – 1048576.
IRowExporter and IRowImporter Interfaces
In RadSpreadStreamProcessing, a row could be exported through the IRowExporter interface. It defines several methods allowing you to add cells to a row or change its appearance.
To read a row and its properties, you should use IRowImporter interface.
Using IRowExporter
A concrete instance of IRowExporter could be created through the CreateRowExporter() method of IWorksheetExporter. Example 1 demonstrates how you can add a row to a worksheet.
Example 1: Create IRowExporter
using (IRowExporter row = worksheet.CreateRowExporter())
{
}
IRowExporter inherits from IDisposable. Make sure the object is disposed when you are done with it. Otherwise, the content won't be written in the exported file. The best way to ensure this is handled properly is to wrap it in a using statement.
In order to customize the way a row appears, you could use one of the following methods:
SetHeightInPixels(): Sets the row height in pixels.
SetHeightInPoints(): Sets the row height in points.
SetOutlineLevel(): Sets the row outline level. The outline level is used when grouping rows. To group several rows, they should have the same OutlineLevel and if you would like to create nested grouping, you can use different levels for the outer and for the nested rows.
SetHidden(): Sets a boolean value that indicates whether the row should be hidden or not.
Example 2: Set properties to IRowExporter
using (IRowExporter row = worksheet.CreateRowExporter())
{
row.SetHeightInPixels(200);
}
Skip Rows
The rows in a document are exported one by one from top to bottom starting from the one with index 0. In order to export a row with a bigger index, you will need to export all the previous rows or skip them.
In some cases you may need to skip several rows and start filling the data in the next one. The IWorksheetExporter interface declares a method that allows you to implement such scenario. Example 3 shows how to skip 5 rows.
Example 3: Skip rows
worksheet.SkipRows(5);
using (IRowExporter row = worksheet.CreateRowExporter())
{
row.SetHidden(true); // The sixth row will be hidden.
}
Read a Row
Using IRowImporter
A concrete instance of IRowImporter could be obtained through the Rows collection of IWorksheetImporter. Example 4 demonstrates how you can start reading a row from a worksheet.
Example 4: Create IRowImporter
foreach (IRowImporter rowImporter in worksheetImporter.Rows)
{
}
The IRowImporter interface exposes the following properties to allow you access its data:
- RowIndex: Gets the index of the row in the worksheet.
- OutlineLevel: Gets the outline level (used when grouping rows).
- IsCustomHeight: Gets a value indicating whether the height applied to the current row is a custom one.
- HeightInPixels and HeightInPoints: Gets the height of the row in pixels and in points, respectively.
- IsHidden: Gets a value determining whether the row is hidden.
- Cells: Collection of ICellImporter objects, enabling you to iterate the cells inside the worksheet using.