Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Looking for a piece of java code
Looking for a piece of java code

public FileOutputStream queryImport(String fileName,String excname,HttpServletRequest request,String startime, String endtime,int year) { FileOutputStream out = null; // Create a new Excel HSSFWorkbook workBook = new HSSFWorkbook(); // Create a sheet page HSSFSheet sheet = workBook.createSheet(); // The sheet page name workBook.setSheetName(0, excname); // Create a header page HSSFHeader header = sheet.getHeader(); // Set the title to be centered header.setCenter ("Data Quality Assessment Report of the First Oil Production Plant"); // Set the first row Header // Set the header style HSSFCellStyle headStyle = workBook.createCellStyle(); HSSFFont headFont = workBook.createFont(); headFont.setFontHeightInPoints((short) 12);// Font size headFont.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);// Bold headStyle.setFont(headFont); headStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// Center left and right headStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// Center top and bottom headStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); headStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); headStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); headStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); headStyle.setTopBorderColor(HSSFColor.BL ACK.index); headStyle .setLeftBorderColor(HSSFColor.BLACK.index); headStyle.setBottomBorderColor(HSSFColor.BLACK.index); headStyle.setRightBorderColor(HSSFColor.BLACK.index); HSSFCellStyle conStyle = workBook.createCellStyle(); HSSFFont headFont1 = workBook.createFont(); headFont1.setFontHeightInPoints((short) 10);//Font size conStyle.setFont(headFont); conStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); conStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); conStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); conStyle.set BorderRight (HSSFCellStyle.BORDER_THIN); conStyle.setTopBorderColor(HSSFColor.BLACK.index); conStyle.setLeftBorderColor(HSSFColor.BLACK.index); conStyle.setBottomBorderColor(HSSFColor.BLACK.index); conStyle.setRightBorderColor(HSSFColor.BLACK.index); Map> map = tableHeadInfo(year); //Create the first row, display the merged table header HSSFRow fristrow = sheet.createRow(0); //The second row, display the column HSSFRow secrow = sheet. createRow(1); int startnum = 0; HSSFCell cellT = null; List collist = new ArrayList(); if (map != null && map.size() > 0) {

< p>int count = 0;

for (String key : map.keySet()) {

List valueList = map.get(key);

startnum = startnum + valueList.size();

// Get all data column names

for (int k = 0; k < valueList.size(); k++) { collist.add(valueList.get(k).toString());

}

// The first row, the cells are merged and displayed

if( key.contains("oth")){//Column is not a merged column//Merge row Region region1 = new Region(0, (short)((startnum - valueList.size())), 1,(short)(startnum -1)); sheet.addMergedRegion(region1); cellT = fristrow.createCell((short) ((startnum - valueList.size()))); cellT.setCellValue(key.substring(0, key.length()- 3)); cellT.setCellStyle(headStyle);

}else{//The column is a merged column Region region1 = new Region(0,(short) ((startnum - valueList.size())), 0,(short) (startnum-1)); sheet.addMergedRegion(region1); cellT = fristrow.createCell((short) ((startnum - valueList.size()))); cellT.setCellValue(key + "(% )"); cellT.setCellStyle(headStyle);

}

//Second line, header display

if (count == (map. size() - 1)) { for (int j = 0; j < collist.size(); j++) { cellT = secrow.createCell((short)(j)); cellT.setCellValue(collist.get(j) ); cellT.setCellStyle(headStyle); sheet.setColumnWidth((short)(j), (short) (3000)); } // The third line, fill the cell with data // Get the result set JSONObject json=dataQualityAssessReportDao. getDataQualityAssessReport(startime, endtime); List? listdataList =(List)json.get("strList"); for (int i = 0; i < listdataList.size(); i++) { //Fill The data starts from the third row, so i needs to be increased by 2 secrow = sheet.createRow((int) i+2); String strvalue = listdataList.get(i); String[] arr = strvalue.split(","); for (int j = 0; j < arr.length; j++) {

cellT = secrow.createCell((short)(j));

if(arr[j] .equals("null")){

cellT.setCellValue("");

}else{

//Remove the green color in the upper left corner of the cell Small triangle symbol;

//When numeric type data is assigned to a cell in string type, a green triangle will appear

if(isNum(arr[j])==true) { cellT.setCellValue(Double.parseDouble(arr[j]));

}else{ cellT.setCellValue(arr[j]);

}

}

cellT.setCellStyle(conStyle); } }

}

count++;

} }?I will give you this example , which means it is similar to what you requested, you can modify it yourself.