Document Solutions for Excel, Java Edition | Document Solutions
Features / Slicer / Slicer Style / Modify Slicer with Custom Style
In This Topic
    Modify Slicer with Custom Style
    In This Topic

    In DsExcel Java, you can define your own custom style and add it in the slicer cache to modify your slicer as per your preferences.

    Refer to the following example code to see how you can modify your slicer with custom style.

    Java
    Copy Code
    // Create slicer cache for table.
    ISlicerCache cache = workbook.getSlicerCaches().add(table, "Category", "categoryCache");
    
    // Add slicer
    ISlicer slicer = cache.getSlicers().add(workbook.getWorksheets().get("Sheet1"), 
    "cate2", "Category", 30, 550,100, 200);
    
    // Create custom slicer style.
    ITableStyle slicerStyle = workbook.getTableStyles().add("test");
            
    // Set ShowAsAvailableSlicerStyle to true, the style will be treated as slicer style.
    slicerStyle.setShowAsAvailableSlicerStyle(true);
    slicerStyle.getTableStyleElements().get(TableStyleElementType.WholeTable).getFont().setName("Arial");
    slicerStyle.getTableStyleElements().get(TableStyleElementType.WholeTable).getFont().setBold(false);
    slicerStyle.getTableStyleElements().get(TableStyleElementType.WholeTable).getFont().setItalic(false);
    slicerStyle.getTableStyleElements().get(TableStyleElementType.WholeTable).getFont()
    .setColor(Color.GetWhite());
    slicerStyle.getTableStyleElements().get(TableStyleElementType.WholeTable).getBorders()
    .setColor(Color.GetLightPink());
    slicerStyle.getTableStyleElements().get(TableStyleElementType.WholeTable).getInterior()
    .setColor(Color.GetLightGreen());
    
    // Set slicer style to custom style.
    slicer.setStyle(slicerStyle);