Commit a89d1f4b authored by Carit Zhu's avatar Carit Zhu 🎱

Version 1.0.2:

1. Modify excel generator to use the year of first data instead of permanent 2018.
parent 13f9be95
...@@ -15,7 +15,7 @@ apply plugin: 'idea' ...@@ -15,7 +15,7 @@ apply plugin: 'idea'
apply plugin: 'org.springframework.boot' apply plugin: 'org.springframework.boot'
group = 'com.example' group = 'com.example'
version = '1.0.1-release' version = '1.0.2-release'
sourceCompatibility = 1.8 sourceCompatibility = 1.8
repositories { repositories {
......
...@@ -53,6 +53,7 @@ public class WarehouseExcel { ...@@ -53,6 +53,7 @@ public class WarehouseExcel {
public HSSFWorkbook downloadExcel() throws Exception { public HSSFWorkbook downloadExcel() throws Exception {
// 创建工作簿对象 // 创建工作簿对象
HSSFWorkbook workbook = new HSSFWorkbook(); HSSFWorkbook workbook = new HSSFWorkbook();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
try { try {
HSSFSheet sheet = workbook.createSheet(fileName); // 创建工作表 HSSFSheet sheet = workbook.createSheet(fileName); // 创建工作表
HSSFCellStyle style = getStyle(workbook); HSSFCellStyle style = getStyle(workbook);
...@@ -89,16 +90,21 @@ public class WarehouseExcel { ...@@ -89,16 +90,21 @@ public class WarehouseExcel {
/* /*
* 创建第二行 * 创建第二行
* */ * */
String year = "";
if (!resultWarehouseNoAndTDLSNAndTimeVo.getDownloadWarehouseVos().isEmpty()){
long timestamp = Long.parseLong(resultWarehouseNoAndTDLSNAndTimeVo.getDownloadWarehouseVos().get(0).getTime());
String dateTime = sdf.format(new Date(timestamp));
year = dateTime.split("-")[0]; // Use the year of first data.
}
HSSFRow row2 = sheet.createRow((short) rowCount); HSSFRow row2 = sheet.createRow((short) rowCount);
HSSFCell cell2 = null; HSSFCell cell2 = row2.createCell(0);
HSSFCellStyle rowStyle2 = getStyle(workbook); HSSFCellStyle rowStyle2 = getStyle(workbook);
cell2 = row2.createCell(0);
for (int n = 0; n < 3; n++) { for (int n = 0; n < 3; n++) {
cell2 = row2.createCell(n); cell2 = row2.createCell(n);
//设置列的格式 //设置列的格式
cell2.setCellStyle(rowStyle2); cell2.setCellStyle(rowStyle2);
//将标题添加到列中 //将标题添加到列中
cell2.setCellValue(i18n.getMessage(request,"year")+ ":2018"); cell2.setCellValue(i18n.getMessage(request,"year")+ ":" + year);
} }
sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 2)); sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 2));
for (int n = 3; n < 6; n++) { for (int n = 3; n < 6; n++) {
...@@ -201,11 +207,10 @@ public class WarehouseExcel { ...@@ -201,11 +207,10 @@ public class WarehouseExcel {
for(int i = 0;i<resultWarehouseNoAndTDLSNAndTimeVo.getDownloadWarehouseVos().size();i++) { for(int i = 0;i<resultWarehouseNoAndTDLSNAndTimeVo.getDownloadWarehouseVos().size();i++) {
HSSFRow row = sheet.createRow((short) rowCount + i); HSSFRow row = sheet.createRow((short) rowCount + i);
HSSFCell cell = null; HSSFCell cell = null;
Long seconds=Long.valueOf(resultWarehouseNoAndTDLSNAndTimeVo.getDownloadWarehouseVos().get(i).getTime()); long timestamp = Long.parseLong(resultWarehouseNoAndTDLSNAndTimeVo.getDownloadWarehouseVos().get(i).getTime());
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); //SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
String time = sdf.format(new Date(seconds)); String dateTime = sdf.format(new Date(timestamp));
String[] t = dateTime.split("-");
String[] t = sdf.format(new Date(seconds)).split("-");
cell2 = row2.createCell(1); cell2 = row2.createCell(1);
cell2.setCellValue(t[0]); cell2.setCellValue(t[0]);
cell2.setCellStyle(rowStyle); cell2.setCellStyle(rowStyle);
......
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