Excel grouping

GemBox.Spreadsheet for Java supports grouping of rows and columns.

In the following example grouping is set both on rows and columns, where rows are expanded and columns are collapsed.

Excel row and column grouping set with GemBox.Spreadsheet
Screenshot of Excel row and column grouping set with GemBox.Spreadsheet
import com.gembox.spreadsheet.*;

class Program {

    public static void main(String[] args) throws java.io.IOException {
        // If using the Professional version, put your serial key below.
        SpreadsheetInfo.setLicense("FREE-LIMITED-KEY");

        ExcelFile workbook = new ExcelFile();
        ExcelWorksheet worksheet = workbook.addWorksheet("Grouping");

        worksheet.getCell(0, 0).setValue("Cell grouping examples:");

        // Vertical grouping.
        worksheet.getCell(2, 0).setValue("GroupA Start");
        worksheet.getRow(2).setOutlineLevel(1);
        worksheet.getCell(3, 0).setValue("A");
        worksheet.getRow(3).setOutlineLevel(1);
        worksheet.getCell(4, 1).setValue("GroupB Start");
        worksheet.getRow(4).setOutlineLevel(2);
        worksheet.getCell(5, 1).setValue("B");
        worksheet.getRow(5).setOutlineLevel(2);
        worksheet.getCell(6, 1).setValue("GroupB End");
        worksheet.getRow(6).setOutlineLevel(2);
        worksheet.getCell(7, 0).setValue("GroupA End");
        worksheet.getRow(7).setOutlineLevel(1);
        // Put outline row buttons above groups.
        worksheet.getViewOptions().setOutlineRowButtonsBelow(false);

        // Horizontal grouping (collapsed).
        worksheet.getCell("E2").setValue("Gr.C Start");
        worksheet.getColumn("E").setOutlineLevel(1);
        worksheet.getColumn("E").setHidden(true);
        worksheet.getCell("F2").setValue("C");
        worksheet.getColumn("F").setOutlineLevel(1);
        worksheet.getColumn("F").setHidden(true);
        worksheet.getCell("G2").setValue("Gr.C End");
        worksheet.getColumn("G").setOutlineLevel(1);
        worksheet.getColumn("G").setHidden(true);
        worksheet.getColumn("H").setCollapsed(true);

        workbook.save("Grouping.%OutputFileType%");
    }
}

See also


Next steps

GemBox.Spreadsheet for Java is a component that enables you to read, write, edit and convert spreadsheet files from your applications using one simple API.

Download Buy