excel标准对比类
This commit is contained in:
@@ -0,0 +1,77 @@
|
|||||||
|
package com.adc.da.slrs.ImportExcelDatas.comment;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
|
import org.apache.poi.ss.usermodel.CellType;
|
||||||
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class Contrast {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(Contrast.class);
|
||||||
|
|
||||||
|
public void run(MultipartFile file,MultipartFile sort) throws IOException {
|
||||||
|
|
||||||
|
InputStream inputStream = file.getInputStream();
|
||||||
|
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
|
||||||
|
|
||||||
|
XSSFSheet sheet = workbook.getSheetAt(0);
|
||||||
|
|
||||||
|
HashSet<String> set = getSet(sort);
|
||||||
|
for (Row row : sheet) {
|
||||||
|
if (row.getCell(0)!=null){
|
||||||
|
//获取表1的标准号
|
||||||
|
String value = row.getCell(0).toString().trim();
|
||||||
|
Cell cell = row.createCell(11);
|
||||||
|
|
||||||
|
//对比在表2中是否存在
|
||||||
|
if (set.contains(value.trim())){
|
||||||
|
logger.info("*");
|
||||||
|
cell.setCellType(CellType.STRING);
|
||||||
|
cell.setCellValue("1");
|
||||||
|
}else {
|
||||||
|
logger.info("-");
|
||||||
|
cell.setCellType(CellType.STRING);
|
||||||
|
cell.setCellValue("0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
File result = new File("C:\\Users\\22501\\Desktop\\foton标准数据\\海外对比全数据.xlsx");
|
||||||
|
FileOutputStream os = new FileOutputStream(result);
|
||||||
|
workbook.write(os);
|
||||||
|
// HashMap<String, String> map = new HashMap<>();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private HashSet<String> getSet(MultipartFile file) throws IOException {
|
||||||
|
InputStream inputStream = file.getInputStream();
|
||||||
|
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
|
||||||
|
|
||||||
|
XSSFSheet sheet = workbook.getSheetAt(0);
|
||||||
|
|
||||||
|
// int lastNum = sheet.getLastRowNum();
|
||||||
|
|
||||||
|
HashSet<String> stringHashSet= new HashSet<>();
|
||||||
|
|
||||||
|
for (Row row : sheet) {
|
||||||
|
if (row.getCell(1)!=null){
|
||||||
|
stringHashSet.add(row.getCell(1).toString().trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return stringHashSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user