Edit this page
Available for: UI for ASP.NET AJAX | UI for ASP.NET MVC | UI for WPF | UI for WinForms | UI for Xamarin

Worksheet View Exporter

The IWorksheetViewExporter interface allows you to manipulate the way the exported document looks like when opened in an application. This article explains the available members of the interface and how you can use it.

Creating Worksheet View Exporter

You can create an instance of the IWorksheetViewExporter interface using the corresponding method of IWorksheetExporter.

[C#] Example 1: Create IWorksheetViewExporter instance

using (IWorksheetViewExporter worksheetView = worksheetExporter.CreateWorksheetViewExporter())
{
    // ...
}

IWorksheetViewExporter 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.

Working with IWorksheetViewExporter

The IWorksheetViewExporter interface allows you perform the following operations:

Change the First Visible Cell

With the IWorksheetViewExporter interface you can set the first visible cell. This cell will be positioned at the top left position of the visible area when the document is rendered. Example 2 shows how you can generate a document containing one worksheet, which, when visualized, will show the C5 cell as the top left cell.

[C#] Example 2: Export a document with first visible cell C5

using (IWorksheetExporter worksheetExporter = workbookExporter.CreateWorksheetExporter("Sheet 1"))
{
    using (IWorksheetViewExporter worksheetView = worksheetExporter.CreateWorksheetViewExporter())
    {
        worksheetView.SetFirstVisibleCell(4, 2);
    }
    // Fill the worksheet.
}

Add Selection to a Document

IWorksheetViewExporter defines methods that allow you apply selection to the exported document so that it contains selection ranges when visualized. You can also change the position of the selection's active cell.

[C#] Example 3: Export a document with applied multiple selection ranges

using (IWorksheetExporter worksheetExporter = workbookExporter.CreateWorksheetExporter("Sheet 1"))
{
    using (IWorksheetViewExporter worksheetView = worksheetExporter.CreateWorksheetViewExporter())
    {
        worksheetView.AddSelectionRange(2, 2, 5, 5);
        worksheetView.AddSelectionRange(4, 4, 8, 8);
        worksheetView.AddSelectionRange(3, 3, 10, 10);
    }
    // Fill the worksheet.
}

[C#] Example 4: Export a document with selection range and specified active cell of the selection

using (IWorksheetExporter worksheet = workbookExporter.CreateWorksheetExporter("Sheet 1"))
{
    using (IWorksheetViewExporter worksheetView = worksheet.CreateWorksheetViewExporter())
    {
        worksheetView.AddSelectionRange(2, 2, 5, 5);
        worksheetView.SetActiveSelectionCell(3, 3);
    }
    // Fill the worksheet with data.
}

Figure 1: Selection with specified active cell

Scale a Document

You can apply a scale factor to the exported document.

[C#] Example 5: Set scale factor

worksheetView.SetScaleFactor(0.5);

Hide Grid Lines and Row or Column Headers

IWorksheetViewExporter enables you to set whether the resultant document should be visualized with grid lines and headers. Example 6 demonstrates how you can hide both, grid lines and row/column headers.

[C#] Example 6: Hide grid lines and row/column headers

worksheetView.SetShouldShowGridLines(false);
worksheetView.SetShouldShowRowColumnHeaders(false);

Freeze Panes

You can freeze panes in the spreadsheet document using the SetFreezePanes() method.

[C#] Example 7: Set freeze panes

worksheetView.SetFreezePanes(4, 6);

Figure 2: Frozen panes

An overload of the SetFreezePanes() method enables you to change the first visible cell of the scrollable pane (the right-bottom pane).

[C#] Example 8: Set freeze panes and change the first visible cell of the scrollable pane

worksheetView.SetFreezePanes(4, 6, 10, 10);

In Figure 3, you can see that the first visible cell of the scrollable pane is K11.

Figure 3: Frozen panes with modified first visible cell of the scrollable pane

See Also