Commit cc2f3402 by Jbb

excel空白行 导致的数据数据过滤一下

parent 6637bdc3
...@@ -221,10 +221,12 @@ public class TbStLayerDataController { ...@@ -221,10 +221,12 @@ public class TbStLayerDataController {
} else { } else {
errorData.setTimeStr(""); errorData.setTimeStr("");
} }
pointList.add(errorData); if(errorData.getxStr() != "" && errorData.getyStr() != "" && errorData.getTitle() != "" && errorData.getTimeStr() != ""){
pointList.add(errorData);
}
} }
} }
/*XSSFWorkbook wb = new XSSFWorkbook(); /* XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet(); XSSFSheet sheet = wb.createSheet();
if(pointList != null && pointList.size() > 0){ if(pointList != null && pointList.size() > 0){
//输出流写入到excel中 //输出流写入到excel中
...@@ -237,32 +239,32 @@ public class TbStLayerDataController { ...@@ -237,32 +239,32 @@ public class TbStLayerDataController {
for (int i = 0; i < pointList.size(); i++) { for (int i = 0; i < pointList.size(); i++) {
TbStLayerData accidentPoint = pointList.get(i); TbStLayerData accidentPoint = pointList.get(i);
String title = accidentPoint.getTitle(); String title = accidentPoint.getTitle();
Date time = accidentPoint.getTime(); String timeStr = accidentPoint.getTimeStr();
String timeFormat = df.format(time); //String timeFormat = df.format(time);
XSSFRow rowData = sheet.createRow(i + 1); XSSFRow rowData = sheet.createRow(i + 1);
rowData.createCell(0).setCellValue(accidentPoint.getxStr()); rowData.createCell(0).setCellValue(accidentPoint.getxStr());
rowData.createCell(1).setCellValue(accidentPoint.getyStr()); rowData.createCell(1).setCellValue(accidentPoint.getyStr());
rowData.createCell(2).setCellValue(title); rowData.createCell(2).setCellValue(title);
rowData.createCell(3).setCellValue(timeFormat); rowData.createCell(3).setCellValue(timeStr);
} }
}*/ }
//通过输出流下载 //通过输出流下载
/*response.setContentType("application/vnd.ms-excel"); response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename=error.xlsx"); response.setHeader("Content-Disposition", "attachment;filename=error.xlsx");
outputStream = response.getOutputStream(); ServletOutputStream outputStream = response.getOutputStream();
//设置文件响应输出格式 //设置文件响应输出格式
ByteArrayOutputStream os = new ByteArrayOutputStream(); // ByteArrayOutputStream os = new ByteArrayOutputStream();
wb.write(os); // wb.write(os);
response.reset(); // response.reset();
response.setContentType("application/msexcel;charset=utf-8"); // response.setContentType("application/msexcel;charset=utf-8");
bytes = os.toByteArray(); // bytes = os.toByteArray();
outputStream.write(bytes); // outputStream.write(bytes);
*//*wb.write(outputStream); wb.write(outputStream);
wb.close(); wb.close();
outputStream.flush(); outputStream.flush();
outputStream.close();*//* outputStream.close();*/
flag = true;*/ /*flag = true;*/
//return null; //return null;
return pointList; return pointList;
} }
......
...@@ -102,7 +102,7 @@ public class CodeGenerator { ...@@ -102,7 +102,7 @@ public class CodeGenerator {
} }
@Test @Test
public void testExcel() throws Exception { public void testExcel() throws Exception {
InputStream is = new FileInputStream("C:\\Users\\JBB\\Desktop\\工作目录\\excel\\模板.xlsx"); InputStream is = new FileInputStream("C:\\Users\\JBB\\Desktop\\工作目录\\excel\\test.xlsx");
XSSFWorkbook sheets = new XSSFWorkbook(is); XSSFWorkbook sheets = new XSSFWorkbook(is);
XSSFSheet sheetAt = sheets.getSheetAt(0); XSSFSheet sheetAt = sheets.getSheetAt(0);
//获取excel有多少行 //获取excel有多少行
...@@ -125,7 +125,7 @@ public class CodeGenerator { ...@@ -125,7 +125,7 @@ public class CodeGenerator {
String wdStr = ""; String wdStr = "";
String titleStr = ""; String titleStr = "";
String dateStr = ""; String dateStr = "";
if (row.getCell(0) != null && row.getCell(1) != null) { if (row.getCell(0) != null && !"".equals(row.getCell(0)) && row.getCell(1) != null && !"".equals(row.getCell(0))) {
row.getCell(0).setCellType(Cell.CELL_TYPE_STRING); row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
row.getCell(1).setCellType(Cell.CELL_TYPE_STRING); row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
/*int cellType = row.getCell(0).getCellType(); /*int cellType = row.getCell(0).getCellType();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment