c# - 从 Excel 文件中读取并插入 Access
问题描述
我是编码新手,但遇到一个问题:我使用 Apache Poi 读取只有一列和大约 20 行的 Excel 文件。我想阅读该信息并将其插入我的 Access 数据库,但我不知道如何。
这是我的第一种方法:
Workbook readWorkbook = WorkbookFactory.create(new FileInputStream(FileChooser.FileChoose()));
Sheet sheet = readWorkbook.getSheetAt(4);
DataFormatter dataFormatter = new DataFormatter();
String cellValue = null;
for (int i = 16; i < 20; i++) { //Statt 20 soll hier 39
Row row = sheet.getRow(i);
if(row == null) {
continue;
}
for (int j = 2; j < 4; j++) {
Cell cell = row.getCell(j);
if(cell == null) {
continue;
}
cellValue = dataFormatter.formatCellValue(cell);
System.out.print(cellValue + "\n");
}
}
return cellValue;
这是我的插入代码:
try {
Connection conn=DriverManager.getConnection("jdbc:ucanaccess://"+FileChooser.FileChoose());
Statement stment = conn.createStatement();
String query = "INSERT INTO Maschine (com_id, typ, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v) VALUES ('"+DatenBankInsert.ForEachLoop()+"')";
stment.executeUpdate(query);
System.out.println("successfull");
}
catch (Exception e) {
System.out.println("Not connected"+e);
}
return null;
解决方案
推荐阅读
- arrays - Google电子表格:如果列中存在某个值+公式
- php - Laravel 5.6:assertSessionHasErrors 导致“违反完整性约束:19 NOT NULL 约束失败”错误
- angular - 带有 AWS-amplify API 和 Auth 意外行为的 Angular 导致 403 未经授权
- excel - 使用 Dim 工作表和单元格的 QueryTables 目标
- java - 如何允许字符串格式的百分比符号获取搜索结果?
- javascript - Vue:如果产品在购物车中,则应用 css 类
- android - 如何正确浏览反编译的 APK 代码?
- sql - SQL 查询以计算每个不同值的出现次数
- django - DRF 可浏览 API 在“django-rest-passwordreset”包中不起作用
- python - 使用 pandas 和 numpy trapz 计算速度(m/s)与时间(每秒)图的曲线下面积(AUC)