List of usage examples for org.apache.poi.hssf.usermodel HSSFRow createCell
@Override public HSSFCell createCell(int column)
From source file:com.lition.service.impl.OwnedServiceImpl.java
/** * POI??// www. ja v a 2 s . c o m */ @Override public InputStream getOutExcelDate() { //1.? String headTitle[] = { "id", "?", "??", "", "??" }; //2.Dao?? List<OwnedVehicle> list = dao.queryAll(); //3.?HSSFWorkbook HSSFWorkbook wb = new HSSFWorkbook(); //4.?sheet HSSFSheet sheet = wb.createSheet("?"); //5.? HSSFCellStyle style = wb.createCellStyle(); // ?? style.setAlignment(HSSFCellStyle.ALIGN_CENTER); style.setVerticalAlignment(HSSFCellStyle.ALIGN_CENTER); //6. HSSFRow row0 = sheet.createRow(0); //7.?? sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4)); HSSFCell row0cell0 = row0.createCell(0); row0cell0.setCellValue("?"); row0cell0.setCellStyle(style); HSSFRow row1 = sheet.createRow(1); for (int i = 0; i < headTitle.length; i++) { HSSFCell row0cell = row1.createCell(i); row0cell.setCellValue(headTitle[i]); row0cell.setCellStyle(style); } for (int i = 0; i < list.size(); i++) { HSSFRow row = sheet.createRow(i + 2); //ID HSSFCell cell0 = row.createCell(0); cell0.setCellValue(list.get(i).getId()); cell0.setCellStyle(style); //? HSSFCell cell1 = row.createCell(1); cell1.setCellValue(list.get(i).getVehicleId()); cell1.setCellStyle(style); //?? HSSFCell cell2 = row.createCell(2); cell2.setCellValue(list.get(i).getDepid()); cell2.setCellStyle(style); // HSSFCell cell3 = row.createCell(3); cell3.setCellValue(list.get(i).getModel()); cell3.setCellStyle(style); //?? HSSFCell cell4 = row.createCell(4); cell4.setCellValue(list.get(i).getVehicleUsageId()); cell4.setCellStyle(style); } //?inputstream; try { OutputStream out = new FileOutputStream("abc.xls"); wb.write(out); out.close(); InputStream in = new FileInputStream("abc.xls"); return in; } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:com.lushapp.common.excel.ExcelUtil.java
License:Apache License
/** * @param excel_name/* ww w. jav a2s . c o m*/ * ?Excel+?? * @param headList * ExcelHead? * @param fieldList * ExcelField? * @param dataList * Excel? * @throws Exception */ public static void createExcel(String excel_name, String[] headList, String[] fieldList, List<Map<String, Object>> dataList) throws Exception { // Excel HSSFWorkbook workbook = new HSSFWorkbook(); // Excel??? // ???""? // HSSFSheet sheet = workbook.createSheet(""); HSSFSheet sheet = workbook.createSheet(); // 0? HSSFRow row = sheet.createRow(0); // =============================================================== for (int i = 0; i < headList.length; i++) { // 0?? HSSFCell cell = row.createCell(i); // ? cell.setCellType(HSSFCell.CELL_TYPE_STRING); // ? cell.setCellValue(headList[i]); } // =============================================================== for (int n = 0; n < dataList.size(); n++) { // 1? HSSFRow row_value = sheet.createRow(n + 1); Map<String, Object> dataMap = dataList.get(n); // =============================================================== for (int i = 0; i < fieldList.length; i++) { // 0?? HSSFCell cell = row_value.createCell(i); // ? cell.setCellType(HSSFCell.CELL_TYPE_STRING); // ? cell.setCellValue(objToString(dataMap.get(fieldList[i]))); } // =============================================================== } // ? FileOutputStream fOut = new FileOutputStream(excel_name); // Excel workbook.write(fOut); fOut.flush(); // ?? fOut.close(); //System.out.println("[" + excel_name + "]" + "?..."); }
From source file:com.lushapp.common.excel.ExcelUtil.java
License:Apache License
/** * @param excel_name//from ww w. j a va 2s. c o m * ?Excel+?? * @param headList * ExcelHead? * @param fieldList * ExcelField? * @param dataList * Excel? * @throws Exception */ public static void createExcel(String excel_name, List<String> headList, List<String> fieldList, List<Map<String, Object>> dataList) throws Exception { // Excel HSSFWorkbook workbook = new HSSFWorkbook(); // Excel??? // ???""? // HSSFSheet sheet = workbook.createSheet(""); HSSFSheet sheet = workbook.createSheet(); // 0? HSSFRow row = sheet.createRow(0); // =============================================================== for (int i = 0; i < headList.size(); i++) { // 0?? HSSFCell cell = row.createCell(i); // ? cell.setCellType(HSSFCell.CELL_TYPE_STRING); // ? cell.setCellValue(headList.get(i)); } // =============================================================== for (int n = 0; n < dataList.size(); n++) { // 1? HSSFRow row_value = sheet.createRow(n + 1); Map<String, Object> dataMap = dataList.get(n); // =============================================================== for (int i = 0; i < fieldList.size(); i++) { // 0?? HSSFCell cell = row_value.createCell(i); // ? cell.setCellType(HSSFCell.CELL_TYPE_STRING); // ? cell.setCellValue(objToString(dataMap.get(fieldList.get(i)))); } // =============================================================== } // ? FileOutputStream fOut = new FileOutputStream(excel_name); // Excel workbook.write(fOut); fOut.flush(); // ?? fOut.close(); //System.out.println("[" + excel_name + "]" + "?..."); }
From source file:com.lushapp.common.excel.ExcelUtil.java
License:Apache License
/** * @param headList//from www . jav a 2 s . c o m * ExcelHead? * @param fieldList * ExcelField? * @param dataList * Excel? * @throws HSSFWorkbook */ public static HSSFWorkbook createExcel(List<String> headList, List<String> fieldList, List<Map<String, Object>> dataList) throws Exception { // Excel HSSFWorkbook workbook = new HSSFWorkbook(); // Excel??? // ???""? // HSSFSheet sheet = workbook.createSheet(""); HSSFSheet sheet = workbook.createSheet(); // 0? HSSFRow row = sheet.createRow(0); // =============================================================== for (int i = 0; i < headList.size(); i++) { // 0?? HSSFCell cell = row.createCell(i); // ? cell.setCellType(HSSFCell.CELL_TYPE_STRING); // ? cell.setCellValue(headList.get(i)); } // =============================================================== for (int n = 0; n < dataList.size(); n++) { // 1? HSSFRow row_value = sheet.createRow(n + 1); Map<String, Object> dataMap = dataList.get(n); // =============================================================== for (int i = 0; i < fieldList.size(); i++) { // 0?? HSSFCell cell = row_value.createCell(i); // ? cell.setCellType(HSSFCell.CELL_TYPE_STRING); // ? cell.setCellValue(objToString(dataMap.get(fieldList.get(i)))); } // =============================================================== } return workbook; }
From source file:com.lushapp.common.excel.ExcelUtil.java
License:Apache License
/** * /*from w w w.ja v a 2 s . c o m*/ * @param excel_name * ?Excel+?? * @param headList * ExcelHead * @param valueList * Excel? * @throws Exception */ public static void bulidExcel(String excel_name, String[] headList, List<String[]> valueList) throws Exception { // Excel HSSFWorkbook workbook = new HSSFWorkbook(); // Excel??? // ???""? // HSSFSheet sheet = workbook.createSheet(""); HSSFSheet sheet = workbook.createSheet(); // 0? HSSFRow row = sheet.createRow(0); // =============================================================== for (int i = 0; i < headList.length; i++) { // 0?? HSSFCell cell = row.createCell(i); // ? cell.setCellType(HSSFCell.CELL_TYPE_STRING); // ? cell.setCellValue(headList[i]); } // =============================================================== for (int n = 0; n < valueList.size(); n++) { // 1? HSSFRow row_value = sheet.createRow(n + 1); String[] valueArray = valueList.get(n); // =============================================================== for (int i = 0; i < valueArray.length; i++) { // 0?? HSSFCell cell = row_value.createCell(i); // ? cell.setCellType(HSSFCell.CELL_TYPE_STRING); // ? cell.setCellValue(valueArray[i]); } // =============================================================== } // ? FileOutputStream fOut = new FileOutputStream(excel_name); // Excel workbook.write(fOut); fOut.flush(); // ?? fOut.close(); //System.out.println("[" + excel_name + "]" + "?..."); }
From source file:com.mmj.app.common.file.ExcelUtils.java
License:Open Source License
/** * excelrow?T??title?T/*from ww w . j a v a 2 s . c o m*/ * * @param response * @param list * @param xlsName * @param headTitle * @return */ public static <T> HSSFWorkbook defBuildExcel(List<T> list, String xlsName, String... headTitle) { return buildExcel(list, xlsName, new IExcel<T>() { @Override public void initHSSRow(List<T> list, HSSFSheet sheet) { HSSFCell cell; for (int j = 0; j < list.size(); j++) { T row = list.get(j); if (row == null) { continue; } HSSFRow hssrow = sheet.createRow(j + 1); Map<String, String> fieldValMap = getFieldValueMap(row); int i = 0; for (Entry<String, String> entry : fieldValMap.entrySet()) { Object value = entry.getValue(); cell = hssrow.createCell(i++); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue(value == null ? StringUtils.EMPTY : value + StringUtils.EMPTY); } } } }, headTitle); }
From source file:com.mmj.app.common.file.ExcelUtils.java
License:Open Source License
/** * excelrow?IExcel.initHSSRow/* ww w.j av a 2s. c om*/ * * @param response * @param list * @param name * @param iExcel * @param headTitle * @return */ public static <T> HSSFWorkbook buildExcel(List<T> list, String name, IExcel<T> iExcel, String... headTitle) { if (list == null || list.size() == 0) { log.error("ExcelUtils buildExcel List<T>:list is null,name={}", name); return null; } if (iExcel == null || Argument.isEmptyArray(headTitle)) { return new HSSFWorkbook(); } String xlsName = name + "_" + DateViewTools.format(new Date(), "yyyy_MM_dd_HH_mm"); // HSSFWorkbook workbook = new HSSFWorkbook(); // HSSFSheet sheet = workbook.createSheet(); workbook.setSheetName(0, xlsName); for (int i = 0; i < headTitle.length; i++) { // ? sheet.setColumnWidth(i, 17 * 256); } HSSFRow rowTitle = sheet.createRow(0); HSSFCell cell = null; for (int i = 0; i < headTitle.length; i++) { // ? cell = rowTitle.createCell(i); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue(headTitle[i]); } // row iExcel.initHSSRow(list, sheet); return workbook; }
From source file:com.modelmetrics.common.poi.ExcelSupport.java
License:Open Source License
public HSSFCell getCell(int cellId, HSSFRow row) { HSSFCell ret = row.createCell((short) cellId); return ret; }
From source file:com.modelmetrics.common.poi.ExcelSupport.java
License:Open Source License
public void decorateRowWithCell(short cellId, HSSFRow row, Object value, HSSFCellStyle cellStyle) { HSSFCell cell = row.createCell(cellId); if (value == null) { } else if (value instanceof Double) { cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(((Double) value).doubleValue()); } else if (value instanceof Integer) { cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(((Integer) value).intValue()); } else {/* www . j av a 2 s.co m*/ cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue(new HSSFRichTextString(value.toString())); } if (cellStyle != null) { cell.setCellStyle(cellStyle); } else { cell.setCellStyle(genericStyle); } }
From source file:com.ms.commons.test.datawriter.impl.ExcelDataWriter.java
License:Open Source License
private void writeRow(HSSFRow row, List<String> list) { short column = 0; for (String item : list) { HSSFCell cell = row.createCell(column++); cell.setCellValue(new HSSFRichTextString((item == null) ? "" : item)); }//from w w w .j a v a2s. c om }