Foreground downloads data stored in excel

@RequestMapping ( "/ download.do") 
public void downloads (years String, String months, the HttpServletResponse Response) throws IOException {
//System.out.println(years+"-"+months);
List <the ProductList> = adminservice Products. findProductByDate (years, months); // query to place the result in no instance of a class ProductList, getter and setter query to the value
String fileName = years + "of" + months + "list of monthly sales";
String = sheetName months + "January sales list";
String TITLENAME years + = "on" + months + "list of monthly sales";
String [] = {columeName "trade name", "sales of goods"};
String [] [] = new new String the Comment [products.size ()] [2];
for (int I = 0; I <products.size (); I ++) {
Comment [I] [0] = products.get (I) .getName ();
comment[i][1]= String.valueOf(products.get(i).getTotalnum());
}
// Create excel file
HSSFWorkbook new new HSSFWorkbook hwb = ();
// Create a sheet in the script hwb
HSSFSheet = hwb.createSheet sheet (sheetName);
// Create a first row
HSSFRow ROW1 = sheet.createRow (0);
/ / create the first cell of the first row of the grid
HSSFCell cell row1.createCell = (0);
// the merged cell
sheet.addMergedRegion (new new CellRangeAddress (0,0,0,1));
cell.setCellValue (TITLENAME);
// Create the second row
HSSFRow ROW2 sheet.createRow = (. 1);
// to two cells in the second row assignment
for (int I = 0; I <2; I ++) {
row2.createCell (I) .setCellValue (columeName [I]);
}
// Create a data line
for (int I = 0; I <comment.length; I ++) {
ROW2 sheet.createRow = (I + 2);
for(int j=0;j<2;j++){
row2.createCell(j).setCellValue(comment[i][j]);
}
}
String filename=fileName+".xls";
response.setContentType("application/ms-excel;charset=UTF-8");
response.setHeader("content-Disposition","attachment;filename="+filename);
OutputStream out =response.getOutputStream();
hwb.write(out);
}

Guess you like

Origin www.cnblogs.com/liuna369-4369/p/10930629.html