该文主要介绍如何使用spire.xls for java在java应用程序中重命名excel工作表和设置工作表标签颜色。
import com.spire.xls.*;
import java.awt.*;
public class renamesheetandsettabcolor {
public static void main(string[] args) {
//加载示例文档
workbook workbook = new workbook();
workbook.loadfromfile("sample.xlsx");
//重命名第一个工作表并设置tab颜色
worksheet worksheet = workbook.getworksheets().get(0);
worksheet.setname("rename1");
worksheet.settabcolor(color.red);
//重命名第二个工作表并设置tab颜色
worksheet = workbook.getworksheets().get(1);
worksheet.setname("rename2");
worksheet.settabcolor(color.green);
//重命名第三个工作表并设置tab颜色
worksheet = workbook.getworksheets().get(2);
worksheet.setname("rename3");
worksheet.settabcolor(color.blue);
//保存文档
workbook.savetofile("output/result.xlsx", excelversion.version2010);
}
}
效果图: