展开全部
添加Spire.Xls.jar依赖,可以创建Excel, 或者对现有Excel文档进行处理。
1. 写入数据到指定单元格62616964757a686964616fe4b893e5b19e31333431376638//Create a Workbook instance
Workbook wb = new Workbook();
//Get the first worksheet
Worksheet sheet = wb.getWorksheets().get(0);
//Write text in the specific cell
sheet.getCellRange(1,1).setText("Hello World");
//Save the file
wb.saveToFile("Hello World.xlsx", ExcelVersion.Version2016)
2. 将数组导入Excel//Create a Workbook instance
Workbook wb = new Workbook();
//Get the first worksheet
Worksheet sheet = wb.getWorksheets().get(0);
//Insert an array to the first column (false if you want to insert data horizontally)
String[] stringArray = new String[]{"Apple","Pear","Grape","Banana","Peach"}
sheet.insertArray(stringArray,1,1,true);
//Save the file
wb.saveToFile("InsertArray.xlsx", ExcelVersion.Version2016);