Document Solutions for Excel, Java Edition | Document Solutions
Features / Group / Create Row or Column Group
In This Topic
    Create Row or Column Group
    In This Topic

    With DsExcel Java, you can apply grouping on rows and columns of a spreadsheet by referring to the following tasks.

    Apply row grouping

    You can apply row grouping by using the group method of the IRange interface and specifying the rows you want to apply grouping on.

    In order to apply row grouping in a worksheet, refer to the following example code.

    Java
    Copy Code
    // 1:20 rows' outline level will be 2.
    worksheet.getRange("1:20").group();
    // 1:10 rows' outline level will be 3.
    worksheet.getRange("1:10").group();

    Apply column grouping

    You can apply column grouping by using the group method of the IRange interface and specifying the columns you want to apply grouping on.

    In order to apply column grouping in a worksheet, refer to the following example code.

    Java
    Copy Code
    // A:N columns' outline level will be 2.
    worksheet.getRange("A:N").group();
    // A:E columns' outline level will be 3.
    worksheet.getRange("A:E").group();

    Set outline level for rows and columns

    While performing the grouping operation for the first time, it displays only the rows arranged into the first level group on the basis of the values of the cells in that particular column. After the first-level grouping, when the view is grouped by any column other than the one used previously, the rows will be arranged in the second level group, third level group and so on.

    In case you want to set the specific outline level for grouping of rows or columns, you can use the setOutlineLevel method of the IRange interface.  You can also choose to display specified levels of row or column groups using the methods of the IOutline interface.

    In order to set the Outline level for rows and columns, refer to the following example code.

    Java
    Copy Code
    // 1:20 rows' outline level will be 3.
    worksheet.getRange("1:20").setOutlineLevel(3);
    
    // A:E columns' outline level will be 4.
    worksheet.getRange("A:E").setOutlineLevel(4);

    You can use the methods of the IOutline interface to figure out whether the summary column is present at the left position or right position of the column groups or whether the summary row is above or below the row groups, respectively.