该文将主要介绍如何在java应用程序中使用spire.xls for java 插入或删除隐藏excel工作表。
首先,请查看示例文档:
添加工作表到excel文档:
import com.spire.xls.*;
public class excelworksheet {
public static void main(string[] args) throws exception {
string inputfile = "sample.xlsx";
string outputfile = "output/addworksheet.xlsx";
//加载示例文档
workbook workbook = new workbook();
workbook.loadfromfile(inputfile);
//添加新的工作表
worksheet sheet = workbook.getworksheets().add("addnewsheet");
sheet.getcellrange("c5").settext("这是新加内容");
//保存文档
workbook.savetofile(outputfile, excelversion.version2010);
}
}
效果图:
删除excel工作表:
import com.spire.xls.*;
public class excelworksheet {
public static void main(string[] args) throws exception {
string inputfile = "sample.xlsx";
string outputfile = "output/removeworksheet.xlsx";
//加载示例文档
workbook workbook = new workbook();
workbook.loadfromfile(inputfile);
//删除第二个工作表
worksheet sheet1 = workbook.getworksheets().get(1);
sheet1.remove();
//保存文档
workbook.savetofile(outputfile, excelversion.version2010);
}
}
删除第二个工作表后的效果图: