1.1HSSF
方式导出(.xls
方式)
private static String PATH = "/Users/impudent/Desktop/";//自己输出的路径
public static void main(String[] args) throws Exception {
//时间
long begin = System.currentTimeMillis();//创建一个工作簿
Workbook workbook = new HSSFWorkbook();
//创建表
Sheet sheet = workbook.createSheet();
//写入数据
for (int rowNumber = 0; rowNumber < 65536; rowNumber++) {
//创建行
Row row = sheet.createRow(rowNumber);
for (int cellNumber = 0; cellNumber < 10; cellNumber++) {
//创建列
Cell cell = row.createCell(cellNumber);
cell.setCellValue(cellNumber);
}
}
System.out.println("结束!");
FileOutputStream fileOutputStream = new FileOutputStream(PATH + "用户信息表-XLS.xls");
workbook.write(fileOutputStream);
fileOutputStream.close();
long end = System.currentTimeMillis();
System.out.println("时间为:"+(double) (end - begin) / 1000);//2.262s
1.2XSSF
方式导出(.xlsx
)
public static String PATH = "/Users/impudent/Desktop/";
public static void main(String[] args) throws Exception {
//时间
long begin = System.currentTimeMillis();//创建一个工作簿
Workbook workbook = new XSSFWorkbook();
//创建表
Sheet sheet = workbook.createSheet();
//写入数据
for (int rowNumber = 0; rowNumber < 65537; rowNumber++) {
Row row = sheet.createRow(rowNumber);
for (int cellNumber = 0; cellNumber < 10; cellNumber++) {
Cell cell = row.createCell(cellNumber);
cell.setCellValue(cellNumber);
}
}
System.out.println("结束");FileOutputStream fileOutputStream = new FileOutputStream(PATH + "用户信息表-XLSX.xlsx");
workbook.write(fileOutputStream);
fileOutputStream.close();
long end = System.currentTimeMillis();
System.out.println((double) (end - begin) / 1000);//5.003s
1.3 SXSSF
方式导出
public static String PATH = "/Users/impudent/Desktop/";
public static void main(String[] args) throws Exception {
//时间
long begin = System.currentTimeMillis();//创建一个工作簿
Workbook workbook = new SXSSFWorkbook();//创建表
Sheet sheet = workbook.createSheet();//写入数据
for (int rowNumber = 0; rowNumber < 100000; rowNumber++) {
Row row = sheet.createRow(rowNumber);
for (int cellNumber = 0; cellNumber < 10; cellNumber++) {
Cell cell = row.createCell(cellNumber);
cell.setCellValue(cellNumber);
}
}
System.out.println("over");FileOutputStream fileOutputStream = new FileOutputStream(PATH + "用户信息表-SXSSF.xlsx");
workbook.write(fileOutputStream);
fileOutputStream.close();
long end = System.currentTimeMillis();
System.out.println((double) (end - begin) / 1000);//6.39s
2.1 Easyexcel
2.1.1 导出操作
public class UserEntity {
@ExcelProperty(value = "姓名")
private String name;@ExcelProperty(value = "年龄")
private int age;@DateTimeFormat(fallbackPatterns = "yyyy-MM-dd HH:mm:ss")
@ExcelProperty(value = "操作时间")
private Date time;public static void main(String[] args) {
List<UserEntity> dataList = new ArrayList<>();
for (int i = 0; i < 10; i++) {
UserEntity userEntity = new UserEntity();
userEntity.setName("张三" + i);
userEntity.setAge(20 + i);
userEntity.setTime(new Date(System.currentTimeMillis() + i));
dataList.add(userEntity);
}
EasyExcel.write("/Users/impudent/Desktop/easyexcel-user1.xls", UserEntity.class).sheet
2.1.2 导入操作
String filePath = "/Users/lixin/Desktop/easyexcel-user1.xls";
List<DemoData> list = EasyExcel.read(filePath).head(UserEntity.class).sheet().doReadSync();
System.out.println(JSONArray.toJSONString(list));