Java rename Excel Sheet and Set Tab Color

This article will introduce how to rename worksheet and set tab color for the sheet in Java applications by using Spire.XLS for Java.

import com.spire.xls.*;
import java.awt.*;

public class RenameSheetandSetTabColor {
    public static void main(String[] args) {
        //Create a workbook and load a file
        Workbook workbook = new Workbook();
        workbook.loadFromFile("Sample.xlsx");

        //Set the new worksheet name and tab color of first worksheet
        Worksheet worksheet = workbook.getWorksheets().get(0);
        worksheet.setName("Rename1");
        worksheet.setTabColor(Color.red);

        //Set the name and tab color of second sheet
        worksheet = workbook.getWorksheets().get(1);
        worksheet.setName("Rename2");
        worksheet.setTabColor(Color.green);

        //Set the name and tab color of third sheet
        worksheet = workbook.getWorksheets().get(2);
        worksheet.setName("Rename3");
        worksheet.setTabColor(Color.blue);

        //Save the document to file
        workbook.saveToFile("output/Result.xlsx", ExcelVersion.Version2010);
    }
}

Effective screenshot:

Java rename Excel Sheet and Set Tab Color