A row is a group of cells located horizontally in the workbook. They appear from left to right in the worksheet and identified through numbers, such as 1, 2, 3, and so on. By default, a worksheet has 1,048,576 rows.
The following sections explain various operations on rows that you can perform in Spread for WPF.
You can insert single or multiple rows at the specified position in a worksheet. Use the InsertRows method of the IWorksheet interface to insert rows.
Refer to the following example code to insert three rows above the second row.
You can hide rows in a worksheet by using the Hidden property of the IRange interface. If the property value is set to true, it hides the row. To show the row again, change the property value to false.
Refer to the following example code to hide rows.
You can delete rows from a worksheet using the RemoveRows method of the IWorksheet interface.
Refer to the following example code to remove three rows starting with row 3.
You can remove all the data and formulas from the specified rows. To clear content, use the IWorksheet's Rows property to reference the row collection and then set the IRange's Clear method.
Refer to the following example code that clears the content of the rows.
You can enable users to move rows by dragging when the value of the DragDropMode enumeration is set to Row. To move a row, click on the row header that you want to move and then drag and drop the header to the desired position.
You can limit the number of rows that you want to display in a worksheet using the RowCount property of the IWorksheet interface.
Refer to the following example code to set the number of rows to 10.
By default, all rows in a worksheet are the same size. To set the desired height of a specific row, use the RowHeight property of the IRange interface. A row height is defined in pixels.
Refer to the following example code to set the height of the row 2 to 100 pixels.
You can expand or reduce the height of the rows in the worksheet. When a user moves the mouse cursor over the row header border, the mouse pointer changes to a resizing shape; dragging the bottom border of the row header to the desired height changes the row size. Similarly, if you want to resize multiple rows, select them and then drag the bottom border of the selected row headers.
By default, resizing row heights is enabled. However, you can prevent resizing by setting the Resizable property of the IRange interface to false.
Refer to the following example code that disables users to resize the rows.
By default, automatic row height adjustment is enabled. When you move the mouse over the border of a row header, the mouse pointer changes to a resizing shape. Double-clicking on the row edge resizes the row to fit the long content of that row to the preferred height. To autofit multiple rows, select them, and double-click on the border between any two row headers in the selection.
You can also specify the automatic fit behavior using the AutoFit method for the rows.
The following example code autofits data in the rows.
You can automatically merge adjacent cells in the same row when their values are equal. To enable this feature, set the MergePolicy enumeration for a specific row, which has the following values.
Value | Description |
None | Do not merge automatically. |
Always | Merge adjacent cells whenever their values are equal. |
Restricted | Adjacent cells are merged if their values are equal and the corresponding range in the previous row are merged. |
The following code sample sets auto-merging for rows 1 and 2 as shown in the above image.
In a spreadsheet control, you can set alternate row colors to the rows of your worksheet by using the AlternatingRows property of the IWorksheetStyles interface. Setting the alternate row colors can improve the readability of your worksheet.
To use this functionality, ensure that the Enabled property of the IAlternatingStyles interface is set to true, which allows the alternate row colors to be applied. You can choose a color from the color list by setting the ThemeColor property of the IInterior interface. This property accepts values from the ThemeColors enumeration.
The following example code sets different colors to the alternate rows(check col page) as shown in the above image.