Document Solutions for Excel, .NET Edition | Document Solutions
Features / Group / Outline Column
In This Topic
    Outline Column
    In This Topic

    Outline columns can be used to organize large amounts of data into meaningful groups.

    DsExcel allows you to add outline columns to view hierarchical data in a tree view and show or hide it from view. The OutlineColumn property of IWorksheet interface can be used to add the outline column. The row outlines are automatically created by adding the outline column. When a worksheet is saved to Excel, the outline column is not displayed but the row outlines are retained.

    The indent level of a cell can be set by using the IndentLevel property of the IRange interface. The maximum indentation level can be set by using MaxLevel property of IOutlineColumn interface whose default value is 10. 

    You can also use the Refresh method of IOutlineColumn interface to rebuild the tree data structure based on the current outline column options and indents.

    The outline column can also be exported to PDF and imported or exported to JSON to interact with SpreadJS.

    Using Code

    Refer to the below example code to create outline column.

    C#
    Copy Code
     IWorkbook workbook = new Workbook();
     IWorksheet worksheet = workbook.Worksheets[0];
    
        //Set data.
        object[,] data = new object[,]{
    { "Preface",                                   "1",       1 } ,
    { "Java SE5 and SE6",                          "1.1",     2 },
    { "Java SE6",                                  "1.1.1",  2 },
    { "The 4th edition",                           "1.2",    2 },
    { "Changes",                                   "1.2.1",  3 },
    { "Note on the cover design",                  "1.3",    4 },
    { "Acknowledgements",                          "1.4",    4 },
    { "Introduction",                              "2",      9 },
    { "Prerequisites",                             "2.1",    9 },
    { "Learning Java",                             "2.2",    10 },
    { "Goals",                                     "2.3",    10 },
    { "Teaching from this book",                   "2.4",    11 },
    { "JDK HTML documentation",                    "2.5",    11 },
    { "Exercises",                                 "2.6",    12 },
    { "Foundations for Java",                      "2.7",    12 },
    { "Source code",                               "2.8",    12 },
    { "Coding standards",                          "2.8.1",  14 },
    { "Errors",                                    "2.9",    14 },
    { "Introduction to Objects",                   "3",      15 },
    { "The progress of abstraction",               "3.1",    15 },
    { "An object has an interface",                "3.2",    17 },
    { "An object provides services",               "3.3",    18 },
    { "The hidden implementation",                 "3.4",    19 },
    { "Reusing the implementation",                "3.5",    20 },
    { "Inheritance",                               "3.6",    21 },
    { "Is-a vs. is-like-a relationships",          "3.6.1",  24 },
    { "Interchangeable objects with polymorphism", "3.7",    25 },
    { "The singly rooted hierarchy",               "3.8",    28 },
    { "Containers",                                "3.9",    28 },
    { "Parameterized types (Generics)",            "3.10",   29 },
    { "Object creation & lifetime",                "3.11",   30 },
    { "Exception handling: dealing with errors",   "3.12",   31 },
    { "Concurrent programming",                    "3.13",   32 },
    { "Java and the Internet",                     "3.14",   33 },
    { "What is the Web?",                          "3.14.1", 33 },
    { "Client-side programming",                   "3.14.2", 34 },
    { "Server-side programming",                   "3.14.3", 38 },
    { "Summary",                                   "3.15",   38 }
    };
        worksheet.Range["A1:C38"].Value = data;
    
        //Set ColumnWidth.
        worksheet.Range["A:A"].ColumnWidthInPixel = 310;
        worksheet.Range["B:C"].ColumnWidthInPixel = 150;
    
        //Set IndentLevel.
        for (int i = 0; i < data.GetLength(0); i++)
        {
            worksheet.Range[i, 0].IndentLevel = (int)data[i, 3];
        }
    
        //Show the summary row above the detail rows.
        worksheet.Outline.SummaryRow = SummaryRow.Above;
    
        //Don't show the row outline when interacting with SJS, the exported excel file still show the row outline.
        worksheet.ShowRowOutline = false;
    
        //Set outline column.
        worksheet.OutlineColumn.ColumnIndex = 0;
        worksheet.OutlineColumn.ShowCheckBox = true;
        worksheet.OutlineColumn.ShowImage = true;
        worksheet.OutlineColumn.MaxLevel = 2;
        worksheet.OutlineColumn.Images.Add(new ImageSource(File.Open("archiverFolder.png", FileMode.Open), ImageType.PNG));
        worksheet.OutlineColumn.Images.Add(new ImageSource(File.Open("newFolder.png", FileMode.Open), ImageType.PNG));
        worksheet.OutlineColumn.Images.Add(new ImageSource(File.Open("docFile.png", FileMode.Open), ImageType.PNG));
        worksheet.OutlineColumn.CollapseIndicator = new ImageSource(File.Open("decreaseIndicator.png", FileMode.Open), ImageType.PNG);
        worksheet.OutlineColumn.ExpandIndicator = new ImageSource(File.Open("increaseIndicator.png", FileMode.Open), ImageType.PNG);
    
        worksheet.OutlineColumn.SetCheckStatus(0, true);
        worksheet.OutlineColumn.SetCollapsed(1, true);
    
        //Print the headings & gridlines.
        worksheet.PageSetup.PrintHeadings = true;
        worksheet.PageSetup.PrintGridlines = true;
    
        //Save to json/excel/pdf.
        workbook.ToJson(new FileStream("outlineColumn1.json", FileMode.Create));
        workbook.Save("outlineColumn1.xlsx");
        workbook.Save("outlineColumn1.pdf");
    Note: The images, checkbox, expand or collapse indicator images are not visible in Excel as it does not supports them but they can be viewed in PDF and SpreadJS.

     The below image shows the Excel output of above code snippet: 

    Excel output

      The below image shows the PDF output of above code snippet:

    PDF output