展开全部
在java程序中添加32313133353236313431303231363533e4b893e5b19e31333433616163Spire.Xls.jar为依赖import com.spire.xls.*;
public class CreateExcel {
public static void main(String[] args) throws Exception {
//创建Workbook对象
Workbook wb = new Workbook();
//获取第一张工作表
Worksheet sheet = wb.getWorksheets().get(0);
//定义一维数据
String[] oneDimensionaArray = new String[]{"Apple", "Pear", "Grape", "Banana", "Peach"};
//从指定单个格开始写入工作表,true表示纵向写入,设置为false为横向写入
sheet.insertArray(oneDimensionaArray, 1, 1, true);
//定义二维数组
String[][] twoDimensionalArray = new String[][]{
{"姓名", "年龄", "性别", "学历"},
{"小王", "25", "男", "本科"},
{"小李", "24", "女", "本科"},
{"小张", "26", "男", "大专"}
};
//从指定单元格开始写入二维数组到工作表
sheet.insertArray(twoDimensionalArray, 1, 3);
//保存文档
wb.saveToFile("output/InsertData.xlsx", ExcelVersion.Version2016);
}
}