GroupDocs.Parser for .NET 24.8 Release Notes

Full List of Issues Covering all Changes in this Release

KeySummaryCategory
PARSERNET-2400Implement the ability to extract sheets from spreadsheetsFeature

Public API and Backward Incompatible Changes

Implement the ability to extract sheets from spreadsheets

Description

This feature allows to extract cells from spreadsheets.

Public API changes

Parser public class was updated with changes as follows:

Features public class was updated with changes as follows:

Added WorksheetCell public class.

Added WorksheetInfo public class.

Added WorksheetRange public class.

Added WorksheetOptions public class.

Usage

The following example shows how to extract cells from spreadsheet:

// Create an instance of Parser class
using (Parser parser = new Parser(Constants.SampleXlsx))
{
    // Check if worksheet cells extraction is supported
    if (!parser.Features.Worksheet)
    {
        throw new NotSupportedException("Worksheet cells extraction isn't supported.");
    }

    // Get the information about worksheets
    IEnumerable<WorksheetInfo> info = parser.GetWorksheetInfo();
   
    // Iterate over worksheet information
    foreach(WorksheetInfo i in info)
    {
        // Print the worksheet name
        Console.WriteLine(i.Name);
        Console.WriteLine();

        // Get the worksheet cells
        IEnumerable<WorksheetCell> cells = parser.GetWorksheetCells(i.Index);

        // Iterate over cells
        foreach (WorksheetCell c in cells)
        {
            // Print the cell information and text value
            Console.WriteLine($"Row: {c.RowIndex} Column: {c.ColumnIndex} RowSpan: {c.RowSpan} ColumnSpan: {c.ColumnSpan}");
            Console.WriteLine(c.Text);
            Console.WriteLine();
        }
    }
}

The following example shows how to extract cells from spreadsheet with customization:

// Create an instance of Parser class
using (Parser parser = new Parser(Constants.SampleXlsx))
{
    // Check if worksheet cells extraction is supported
    if (!parser.Features.Worksheet)
    {
        throw new NotSupportedException("Worksheet cells extraction isn't supported.");
    }

    // Get the information about the first worksheet
    WorksheetInfo info = parser.GetWorksheetInfo(0);

    // Print the worksheet name
    Console.WriteLine(info.Name);
    Console.WriteLine();

    // Create the range that represents the first two rows
    WorksheetRange range = new WorksheetRange(
        info.MinRowIndex,
        Math.Min(info.MinRowIndex + 1, info.MaxRowIndex),
        info.MinColumnIndex,
        info.MaxColumnIndex);

    // Get the worksheet cells from the first two rows
    IEnumerable<WorksheetCell> cells = parser.GetWorksheetCells(0, new WorksheetOptions(range));

    // Iterate over cells
    foreach (WorksheetCell c in cells)
    {
        // Print the cell information and text value
        Console.WriteLine($"Row: {c.RowIndex} Column: {c.ColumnIndex} RowSpan: {c.RowSpan} ColumnSpan: {c.ColumnSpan}");
        Console.WriteLine(c.Text);
        Console.WriteLine();
    }
}