parent
3661db4db2
commit
d6ee261bab
@ -1,4 +1,4 @@
|
||||
package UnitTest.ImportExcel.Test;
|
||||
package UnitTest.ImportExcel;
|
||||
|
||||
import com.aspose.cells.Cell;
|
||||
import com.aspose.cells.Workbook;
|
@ -1,4 +1,4 @@
|
||||
package UnitTest.ImportExcel.Test;
|
||||
package UnitTest.ImportExcel;
|
||||
|
||||
import com.dsideal.QingLong.Start;
|
||||
import com.jfinal.kit.PropKit;
|
@ -0,0 +1,62 @@
|
||||
package UnitTest.ImportExcel;
|
||||
|
||||
import cn.hutool.poi.excel.ExcelReader;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
|
||||
import com.jfinal.kit.PropKit;
|
||||
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
||||
import com.jfinal.plugin.activerecord.CaseInsensitiveContainerFactory;
|
||||
import com.jfinal.plugin.activerecord.dialect.PostgreSqlDialect;
|
||||
import com.jfinal.plugin.hikaricp.HikariCpPlugin;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ImportExcelTemplate {
|
||||
public static void main(String[] args) throws IOException {
|
||||
//告之配置文件位置
|
||||
PropKit.use("application.properties");
|
||||
HikariCpPlugin hp = new HikariCpPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"),
|
||||
PropKit.get("password").trim(), PropKit.get("driverClassName"));
|
||||
hp.start();
|
||||
// 配置ActiveRecord插件
|
||||
ActiveRecordPlugin arp = new ActiveRecordPlugin(hp);
|
||||
//配置默认小写
|
||||
arp.setContainerFactory(new CaseInsensitiveContainerFactory(true));
|
||||
|
||||
arp.setDialect(new PostgreSqlDialect());
|
||||
arp.start();
|
||||
// Excel文件的路径
|
||||
String filePath = "D:\\dsWork\\QingLong\\src\\main\\java\\UnitTest\\ImportExcel\\Excel\\Example.xlsx";
|
||||
|
||||
try {
|
||||
FileInputStream file = new FileInputStream(filePath);
|
||||
Workbook workbook = new XSSFWorkbook(file);
|
||||
|
||||
List<List<List<String>>> allSheets = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
|
||||
Sheet sheet = workbook.getSheetAt(i);
|
||||
System.out.println("Sheet name: " + sheet.getSheetName());
|
||||
|
||||
for (Row row : sheet) {
|
||||
List<String> rowData = new ArrayList<>();
|
||||
for (Cell cell : row) {
|
||||
cell.setCellType(CellType.STRING);
|
||||
rowData.add(cell.getStringCellValue());
|
||||
}
|
||||
System.out.println(rowData);
|
||||
}
|
||||
}
|
||||
workbook.close();
|
||||
file.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue