Document Solutions for Excel, Java Edition | Document Solutions
Features / Worksheet / Customize Worksheets
In This Topic
    Customize Worksheets
    In This Topic

    DsExcel Java allows you to customize worksheets using the methods of the IWorksheet interface. You can perform useful operations like customizing gridlines to modify row and column headers, setting color for the tabs, or setting default height and width for rows and columns, and so much more.

    Customizing a worksheet to modify the default settings involves the following tasks:

    Configure display

    You can modify the display settings of your worksheet from left to right or right to left.

    In order to configure the display of your worksheet as per your preferences, refer to the following example code.

    Java
    Copy Code
    // Configure Sheet Settings
    Workbook workbook = new Workbook();
            
    // Fetch the default worksheet
    IWorksheet worksheet = workbook.getWorksheets().get(0);
            
    // Assign the values to the cells
    worksheet.getRange("B1").setValue("ABCD");
    worksheet.getRange("B2").setValue(3);
    worksheet.getRange("C1").setValue("Documents");
    worksheet.getRange("C2").setValue(4);
    worksheet.getRange("D1").setValue("Google");
    worksheet.getRange("D2").setValue("ABCD");
    worksheet.getSheetView().setDisplayRightToLeft(true);

    Set the tab color

    You can change the default tab color of your worksheet using the setTabColor method of the IWorksheet interface.

    In order to set the tab color for your worksheet as per your preferences, refer to the following example code.

    Java
    Copy Code
    // Set the tab color of the specified sheet as green.
    worksheet.setTabColor(Color.GetGreen());

    Set visibility

    You can show or hide your worksheet using the setVisible method of the IWorksheet interface.

    In order to set the visibility of your worksheet, refer to the following example code.

    Java
    Copy Code
    // Adding new sheet and set the visibility of the sheet as Hidden.
    IWorksheet worksheet1 = workbook.getWorksheets().add();
    worksheet1.setVisible(Visibility.Hidden);

    Set background image

    You can set a custom background image to your worksheet using the setBackgroundPicture() method of the IWorksheet interface. With this feature, users can insert any background image to the worksheet including their organization logo, custom watermark or a wallpaper of their choice without any hassles.

    Refer to the following example code in order to set a custom background image in your worksheet.

    Java
    Copy Code
            
    // Fetch default worksheet
    IWorksheet worksheet = workbook.getWorksheets().get(0);
    
    // To load an image from a specific file in input stream
    InputStream inputStream = ClassLoader.getSystemResourceAsStream("Logo.png");
    try {
        byte[] bytes = new byte[inputStream.available()];
        // Read an image from input stream
        inputStream.read(bytes, 0, bytes.length);
    
        // Setting worksheet's BackgroundPicture
        worksheet.setBackgroundPicture(bytes);
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
            

    Define standard width and height

    You can define the standard height and width of your worksheet using the setStandardHeight and setStandardWidth methods of the IWorksheet interface, respectively.

    In order to define the standard width and height as per your requirements, refer to the following example code.

    Java
    Copy Code
    // Setting the height and width of the worksheet
    worksheet.setStandardHeight(20);
    worksheet.setStandardWidth(40);
    See Also