1、可在e-iceblue中文官网下载包,解压后,将lib文件夹中的jar文件导入Java程序;或者通过maven仓库下载导入jar,maven仓库路径配置及依赖添加可以参考官网教程。导入效果如下图:

1、import com.spire.xls.*;
public class InsertRowAndColumn {
public static void main(String[] args) {
//加载文档
Workbook wb = new Workbook();
wb.loadFromFile("test.xlsx");
//获取工作表
Worksheet sheet = wb.getWorksheets().get(0);
sheet.insertRow(2);//在第2行插入默认格式的行
//sheet.insertRow(2,2);//在第2行插入默认格式的两行
//sheet.insertRow(5,1,InsertOptionsType.FormatAsAfter);//在第5行插入和下一行格式相同的两行
sheet.insertColumn(3);//在第3列插入默认格式的列
//sheet.insertColumn(3,2);//在第3列插入默认格式的两列
//sheet.insertColumn(3,1,InsertOptionsType.FormatAsBefore);//在第3列插入和前一列格式相同的一列
//保存文档
wb.saveToFile("InsertRowAndColumn.xlsx");
wb.dispose();
}
}
2、不带格式插入一行或列,效果图:

3、不带格式插入两行或列,效果图:

4、带格式插入一行或列,效果图:
