This article will show you how to use Spire.XLS for java to rename worksheets and set tab colors for sheets in Java applications. Tools used: Free Spire.XLS for Java (free version) Getting and installing Jar files:
Method 1: Download the jar file bag through the homepage. After downloading, unzip the file and put the Spire.xls.jar file under the lib folder into the Java program. Introduce to.
Method 2: maven warehouse Introduction by installation.
import com.spire.xls.*;
import java.awt.*;
public class RenameSheetandSetTabColor {
public static void main(String[] args) {
//Import an Excel document
Workbook workbook = new Workbook();
workbook.loadFromFile("Sample.xlsx");
//Set the new worksheet name and tab color for the first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
worksheet.setName("Rename1");
worksheet.setTabColor(Color.red);
//Set the name of the second sheet and the color of the tab
worksheet = workbook.getWorksheets().get(1);
worksheet.setName("Rename2");
worksheet.setTabColor(Color.green);
//Set the name of the third sheet and the color of the tab
worksheet = workbook.getWorksheets().get(2);
worksheet.setName("Rename3");
worksheet.setTabColor(Color.blue);
//Save the document to a file
workbook.saveToFile("output/Result.xlsx", ExcelVersion.Version2010);
}
}
Effect diagram:
Recommended Posts