ai中excel的解析
This commit is contained in:
parent
46d68f8d4b
commit
862eb216e5
|
|
@ -1,8 +1,12 @@
|
||||||
package com.electromagnetic.industry.software.common.pojo;
|
package com.electromagnetic.industry.software.common.pojo;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
public class PageFile {
|
public class PageFile {
|
||||||
|
|
||||||
private int pageNumber;
|
private int pageNumber;
|
||||||
|
|
@ -10,4 +14,6 @@ public class PageFile {
|
||||||
private String content;
|
private String content;
|
||||||
|
|
||||||
private String fileName;
|
private String fileName;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
@ -229,14 +230,52 @@ public class OfficeFileUtil {
|
||||||
return EleCommonUtil.formateString(stringBuilder.toString());
|
return EleCommonUtil.formateString(stringBuilder.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<PageFile> parseXlsxByPage(String filePath) {
|
public static List<PageFile> parseXlsxByPage(String filePath) throws IOException {
|
||||||
|
List<PageFile> pageFiles = new ArrayList<>();
|
||||||
return null;
|
XSSFWorkbook excel = new XSSFWorkbook(FileUtil.getInputStream(filePath));
|
||||||
|
int activeSheetIndex = excel.getNumberOfSheets();
|
||||||
|
String fileName = new File(filePath).getName();
|
||||||
|
for (int i = 0; i < activeSheetIndex; i++) {
|
||||||
|
XSSFSheet sheet = excel.getSheetAt(i);
|
||||||
|
int allRows = sheet.getPhysicalNumberOfRows();
|
||||||
|
StringBuilder content = new StringBuilder();
|
||||||
|
for (int j = 0; j < allRows; j++) {
|
||||||
|
XSSFRow row = sheet.getRow(j);
|
||||||
|
if (Objects.isNull(row)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (Cell cell : row) {
|
||||||
|
content.append(getCellValue(cell)).append("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pageFiles.add(new PageFile(i, content.toString(), fileName));
|
||||||
|
}
|
||||||
|
excel.close();
|
||||||
|
return pageFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<PageFile> parseXlsByPage(String filePath) {
|
public static List<PageFile> parseXlsByPage(String filePath) throws IOException {
|
||||||
|
List<PageFile> pageFiles = new ArrayList<>();
|
||||||
return null;
|
Workbook sheets = WorkbookFactory.create(FileUtil.getInputStream(filePath));
|
||||||
|
String fileName = new File(filePath).getName();
|
||||||
|
int numberOfSheets = sheets.getNumberOfSheets();
|
||||||
|
for (int i = 0; i < numberOfSheets; i++) {
|
||||||
|
Sheet sheet = sheets.getSheetAt(i);
|
||||||
|
int allRows = sheet.getPhysicalNumberOfRows();
|
||||||
|
StringBuilder content = new StringBuilder();
|
||||||
|
for (int j = 0; j < allRows; j++) {
|
||||||
|
Row row = sheet.getRow(j);
|
||||||
|
if (Objects.isNull(row)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (Cell cell : row) {
|
||||||
|
content.append(getCellValue(cell)).append("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pageFiles.add(new PageFile(i, content.toString(), fileName));
|
||||||
|
}
|
||||||
|
sheets.close();
|
||||||
|
return pageFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue