List of usage examples for org.apache.poi.hssf.usermodel HSSFCell setCellValue
@SuppressWarnings("fallthrough") public void setCellValue(boolean value)
From source file:com.zdtx.ifms.specific.service.task.FuelMileageManager.java
@SuppressWarnings("unchecked") public InputStream getData(Page<Mileageoil> page, List<Mileageoil> list, FuelMileageVo fmvo) { //Page<Mileageoil> pageResult = this.getBetch(page, fmvo); Page<Mileageoil> page_export = (Page<Mileageoil>) Struts2Util.getSession().getAttribute("page_export"); DetachedCriteria criteria_export = (DetachedCriteria) Struts2Util.getSession() .getAttribute("criteria_export"); List<Order> orderList_export = (List<Order>) Struts2Util.getSession().getAttribute("orderList_export"); page_export.setPageSize(page_export.getTotalCount()); Page<Mileageoil> pageResult = baseDao.getBatch(page_export, criteria_export.getExecutableCriteria(baseDao.getSession()), orderList_export); List<Mileageoil> data = new ArrayList<Mileageoil>(); if (null != pageResult) { if (0 != pageResult.getResult().size()) { data = pageResult.getResult(); }/*ww w . j av a 2 s . c om*/ } ExportExcel ee = new ExportExcel() { @Override protected HSSFWorkbook disposeData(HSSFWorkbook wb, Object[] total, List<?> data) throws IOException { HSSFSheet sheet = wb.getSheetAt(0); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6)); HSSFRow rowss = sheet.createRow(0); rowss.setHeightInPoints(20); HSSFCell hssfCell = rowss.createCell(0); hssfCell = this.createCell(wb, hssfCell, "Fuel Mileage"); HSSFCellStyle style = this.createStyle(wb); HSSFRow row2 = sheet.createRow(1); HSSFCell cellrow01 = row2.createCell(0); cellrow01.setCellStyle(style); HSSFCell cellrow02 = row2.createCell(1); cellrow02.setCellStyle(style); HSSFCell cellrow03 = row2.createCell(2); cellrow03.setCellStyle(style); HSSFCell cellrow04 = row2.createCell(3); cellrow04.setCellStyle(style); HSSFCell cellrow05 = row2.createCell(4); cellrow05.setCellStyle(style); HSSFCell cellrow06 = row2.createCell(5); cellrow06.setCellStyle(style); cellrow01.setCellValue("No."); cellrow02.setCellValue("Plate Number"); cellrow03.setCellValue("Vehicle Type"); cellrow04.setCellValue("Date"); cellrow05.setCellValue("Mileage"); cellrow06.setCellValue("Fuel consumption"); if (null != data && 0 != data.size()) { for (int i = 0; i < data.size(); i++) { HSSFRow row = sheet.createRow(i + 2); Mileageoil o = (Mileageoil) data.get(i); HSSFCell cell001 = row.createCell(0); cell001.setCellStyle(style); cell001.setCellValue(i + 1); HSSFCell cell002 = row.createCell(1); cell002.setCellStyle(style); cell002.setCellValue(o.getVehiclename()); HSSFCell cell003 = row.createCell(2); cell003.setCellStyle(style); cell003.setCellValue(o.getTypename()); HSSFCell cell004 = row.createCell(3); cell004.setCellStyle(style); cell004.setCellValue(o.getRiqi()); HSSFCell cell005 = row.createCell(4); cell005.setCellStyle(style); cell005.setCellValue(o.getMileage() + "m"); HSSFCell cell006 = row.createCell(5); cell006.setCellStyle(style); cell006.setCellValue(o.getOilcost() == null ? "0" : o.getOilcost() + "L"); } } return wb; } }; Object[] total = new Object[1]; total[0] = ""; String str = "Fuel Mileage"; return ee.export(total, data, str); }
From source file:com.zdtx.ifms.specific.service.vehicle.VehicleListManager.java
@SuppressWarnings("unchecked") public InputStream getExcel(String title) { List<VehcileView> data = new ArrayList<VehcileView>(); Page<VehcileView> page_export = (Page<VehcileView>) Utils.getSession().getAttribute("page_export"); DetachedCriteria criteria_export = (DetachedCriteria) Utils.getSession().getAttribute("criteria_export"); List<Order> orderList_export = (List<Order>) Utils.getSession().getAttribute("orderList_export"); page_export.setPageSize(page_export.getTotalCount()); Page<VehcileView> pageResult = baseDao.getBatch(page_export, criteria_export.getExecutableCriteria(baseDao.getSession()), orderList_export); if (null != pageResult) { if (0 != pageResult.getResult().size()) { data = pageResult.getResult(); }//from w w w . j a v a 2s . c om } ExportExcel ee = new ExportExcel() { @Override protected HSSFWorkbook disposeData(HSSFWorkbook wb, Object[] total, List<?> data) throws IOException { HSSFSheet sheet = wb.getSheetAt(0); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3)); HSSFRow rowss = sheet.createRow(0); rowss.setHeightInPoints(20); HSSFCell hssfCell = rowss.createCell(0); hssfCell = this.createCell(wb, hssfCell, total[0].toString()); HSSFCellStyle style = this.createStyle(wb); HSSFRow row2 = sheet.createRow(1); HSSFCell cellrow01 = row2.createCell(0); cellrow01.setCellStyle(style); HSSFCell cellrow02 = row2.createCell(1); cellrow02.setCellStyle(style); HSSFCell cellrow03 = row2.createCell(2); cellrow03.setCellStyle(style); HSSFCell cellrow04 = row2.createCell(3); cellrow04.setCellStyle(style); HSSFCell cellrow05 = row2.createCell(4); cellrow05.setCellStyle(style); HSSFCell cellrow06 = row2.createCell(5); cellrow06.setCellStyle(style); HSSFCell cellrow07 = row2.createCell(6); cellrow07.setCellStyle(style); HSSFCell cellrow08 = row2.createCell(7); cellrow08.setCellStyle(style); HSSFCell cellrow09 = row2.createCell(8); cellrow09.setCellStyle(style); HSSFCell cellrow10 = row2.createCell(9); cellrow10.setCellStyle(style); cellrow01.setCellValue("No."); cellrow02.setCellValue("Plate Number"); cellrow03.setCellValue("Fleet"); cellrow04.setCellValue("Department"); cellrow05.setCellValue("Device"); cellrow06.setCellValue("Vehicle Type"); cellrow07.setCellValue("Vehicle Brand"); cellrow08.setCellValue("Key Code"); cellrow09.setCellValue("IP"); cellrow10.setCellValue("Description"); if (null != data && 0 != data.size()) { for (int i = 0; i < data.size(); i++) { VehcileView a = (VehcileView) data.get(i); HSSFRow row = sheet.createRow(i + 2); HSSFCell cell001 = row.createCell(0); cell001.setCellStyle(style); cell001.setCellValue(i + 1); HSSFCell cell002 = row.createCell(1); cell002.setCellStyle(style); cell002.setCellValue(a.getVehiclename()); HSSFCell cell003 = row.createCell(2); cell003.setCellStyle(style); cell003.setCellValue(a.getFleetname()); HSSFCell cell004 = row.createCell(3); cell004.setCellStyle(style); cell004.setCellValue(a.getDeptname()); HSSFCell cell005 = row.createCell(4); cell005.setCellStyle(style); cell005.setCellValue(a.getDevicename()); HSSFCell cell006 = row.createCell(5); cell006.setCellStyle(style); cell006.setCellValue(a.getTypename()); HSSFCell cell007 = row.createCell(6); cell007.setCellStyle(style); cell007.setCellValue(a.getBrandname()); HSSFCell cell008 = row.createCell(7); cell008.setCellStyle(style); cell008.setCellValue(a.getKeycode()); HSSFCell cell009 = row.createCell(8); cell009.setCellStyle(style); cell009.setCellValue(a.getCctvip()); HSSFCell cell010 = row.createCell(9); cell010.setCellStyle(style); cell010.setCellValue(a.getDescription()); } } return wb; } }; Object[] total = new Object[1]; total[0] = title; String str = title; return ee.export(total, data, str); }
From source file:com.zhu.action.CarAction.java
public void exportpeople(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {//from www . j a v a 2s . c o m CarForm carForm = (CarForm) form; // webbookExcel HSSFWorkbook wb = new HSSFWorkbook(); // webbooksheet,Excelsheet HSSFSheet sheet = wb.createSheet("?"); // sheet0,??poiExcel?short HSSFRow row = sheet.createRow((int) 0); // ? HSSFCellStyle style = wb.createCellStyle(); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // ? HSSFCell cell = row.createCell(0); cell.setCellValue("??"); cell.setCellStyle(style); cell = row.createCell(1); cell.setCellValue("???"); cell.setCellStyle(style); // ? ?? OrderService orderService = new OrderService(); List<Orderinfo> list = orderService.getOrderCarDetail(carForm.getId()); System.out.println(list.size()); for (int i = 0; i < list.size(); i++) { row = sheet.createRow(i + 1); Orderinfo order = (Orderinfo) list.get(i); // ? row.createCell(0).setCellValue(order.getN1()); row.createCell(1).setCellValue(order.getI1()); row = sheet.createRow(i + list.size() + 1); row.createCell(0).setCellValue(order.getN2()); row.createCell(1).setCellValue(order.getI2()); row = sheet.createRow(i + list.size() + list.size() + 1); row.createCell(0).setCellValue(order.getN3()); row.createCell(1).setCellValue(order.getI3()); row = sheet.createRow(i + list.size() + list.size() + list.size() + 1); row.createCell(0).setCellValue(order.getN4()); row.createCell(1).setCellValue(order.getI4()); row = sheet.createRow(i + list.size() + list.size() + list.size() + list.size() + 1); row.createCell(0).setCellValue(order.getN5()); row.createCell(1).setCellValue(order.getI5()); row = sheet.createRow(i + list.size() + list.size() + list.size() + list.size() + list.size() + 1); row.createCell(0).setCellValue(order.getN6()); row.createCell(1).setCellValue(order.getI6()); row = sheet.createRow( i + list.size() + list.size() + list.size() + list.size() + list.size() + list.size() + 1); row.createCell(0).setCellValue(order.getN7()); row.createCell(1).setCellValue(order.getI7()); row = sheet.createRow(i + list.size() + list.size() + list.size() + list.size() + list.size() + list.size() + list.size() + 1); row.createCell(0).setCellValue(order.getN8()); row.createCell(1).setCellValue(order.getI8()); row = sheet.createRow(i + list.size() + list.size() + list.size() + list.size() + list.size() + list.size() + list.size() + list.size() + 1); row.createCell(0).setCellValue(order.getN9()); row.createCell(1).setCellValue(order.getI9()); row = sheet.createRow(i + list.size() + list.size() + list.size() + list.size() + list.size() + list.size() + list.size() + list.size() + list.size() + 1); row.createCell(0).setCellValue(order.getN10()); row.createCell(1).setCellValue(order.getI10()); } // ? String filePath = ""; Date dt = new Date(); DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); String date = df.format(dt).toString(); filePath = "/Users/Nemo/Documents/carpeople" + date + ".xls"; File file = new File(filePath); try { // FileOutputStream fout = new FileOutputStream( // "/Users/Nemo/Documents/carpeople.xls"); // wb.write(fout); // fout.close(); OutputStream out = new FileOutputStream(file); wb.write(out); out.close(); } catch (Exception e) { e.printStackTrace(); } int key = 0; int MaxRowNum = 0, MaxCellNum = 0; try { FileInputStream in = new FileInputStream(filePath); POIFSFileSystem fs = new POIFSFileSystem(in); HSSFWorkbook workbook = new HSSFWorkbook(fs); FileOutputStream out = new FileOutputStream("/Users/Nemo/Documents/carpeople" + date + ".xls"); int number = workbook.getNumberOfSheets(); for (int i = 0; i < number; i++) { // ?sheet sheet = workbook.getSheetAt(i); // 14 System.out.println("" + sheet.getSheetName() + " ? " + (sheet.getLastRowNum() + 1)); MaxRowNum = 0; for (int k = 0; k <= sheet.getLastRowNum(); k++) { HSSFRow hRow = sheet.getRow(k); // System.out.println((k + 1) + ""); if (isBlankRow(hRow)) // { int m = 0; for (m = k + 1; m <= sheet.getLastRowNum(); m++) { HSSFRow nhRow = sheet.getRow(m); if (!isBlankRow(nhRow)) { // System.out.println("?" + (m + 1)); sheet.shiftRows(m, sheet.getLastRowNum(), k - m); break; } } if (m > sheet.getLastRowNum()) break; // ? } else { // ? MaxRowNum++; if (MaxCellNum < hRow.getLastCellNum()) MaxCellNum = hRow.getLastCellNum(); } } workbook.setPrintArea(i, 0, MaxCellNum, 0, MaxRowNum); System.out .println("?? " + sheet.getSheetName() + " " + MaxRowNum); } workbook.write(out); in.close(); out.close(); } catch (IOException e) { System.out.println(key + " " + e.getMessage() + " "); e.printStackTrace(); } System.out.println("??"); }
From source file:com.zhu.action.CarAction.java
public void export(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {/*w w w . ja v a2 s.co m*/ // webbookExcel HSSFWorkbook wb = new HSSFWorkbook(); // webbooksheet,Excelsheet HSSFSheet sheet = wb.createSheet("?"); // sheet0,??poiExcel?short HSSFRow row = sheet.createRow((int) 0); // ? HSSFCellStyle style = wb.createCellStyle(); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // ? HSSFCell cell = row.createCell(0); cell.setCellValue("id"); cell.setCellStyle(style); cell = row.createCell(1); cell.setCellValue("?"); cell.setCellStyle(style); cell = row.createCell(2); cell.setCellValue(""); cell.setCellStyle(style); cell = row.createCell(3); cell.setCellValue(""); cell.setCellStyle(style); cell = row.createCell(4); cell.setCellValue(""); cell.setCellStyle(style); cell = row.createCell(5); cell.setCellValue(""); cell.setCellStyle(style); cell = row.createCell(6); cell.setCellValue(""); cell.setCellStyle(style); cell = row.createCell(7); cell.setCellValue("?"); cell.setCellStyle(style); cell = row.createCell(8); cell.setCellValue("?"); cell.setCellStyle(style); // ? ?? CarService carService = new CarService(); List<Car> list = carService.getCar(); for (int i = 0; i < list.size(); i++) { row = sheet.createRow((int) i + 1); Car car = (Car) list.get(i); // ? row.createCell(0).setCellValue(car.getId()); row.createCell(1).setCellValue(car.getCarid()); row.createCell(2).setCellValue(car.getLicense()); row.createCell(3).setCellValue(car.getNumber()); row.createCell(4).setCellValue(car.getPeople()); row.createCell(5).setCellValue(car.getRoute()); row.createCell(6).setCellValue(car.getStartdate()); row.createCell(7).setCellValue(car.getEnddate()); if (car.getStatus() == 0) { row.createCell(8).setCellValue(""); } else if (car.getStatus() == 1) { row.createCell(8).setCellValue(""); } else { row.createCell(8).setCellValue(""); } // cell = row.createCell((short) 3); } // ? String filePath = ""; Date dt = new Date(); DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); String date = df.format(dt).toString(); filePath = "/Users/Nemo/Documents/car" + date + ".xls"; File file = new File(filePath); try { FileOutputStream fout = new FileOutputStream(file); wb.write(fout); fout.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:control.listaEquipos.java
private boolean generaExcel(String path) { // Se crea el libro HSSFWorkbook libro = new HSSFWorkbook(); // Se crea una hoja dentro del libro HSSFSheet hoja = libro.createSheet("Equipos"); // Se crea una fila dentro de la hoja HSSFRow fila = hoja.createRow(0);//from w ww.j a v a 2 s .co m // Se crea una celda dentro de la fila HSSFCell celda = fila.createCell((short) 0); HSSFRichTextString texto = new HSSFRichTextString("Id "); celda.setCellValue(texto); celda = fila.createCell((short) 1); texto = new HSSFRichTextString("Nombre"); celda.setCellValue(texto); celda = fila.createCell((short) 2); texto = new HSSFRichTextString("Categoria"); celda.setCellValue(texto); celda = fila.createCell((short) 3); texto = new HSSFRichTextString("Accesorios"); celda.setCellValue(texto); celda = fila.createCell((short) 4); texto = new HSSFRichTextString("Descripcion"); celda.setCellValue(texto); celda = fila.createCell((short) 5); texto = new HSSFRichTextString("Marca"); celda.setCellValue(texto); celda = fila.createCell((short) 6); texto = new HSSFRichTextString("Estado"); celda.setCellValue(texto); int nr = 1; Object[][] tabla = this.getTableData(tabEquipo); for (Object[] o : tabla) { fila = hoja.createRow(nr); int i = 0; for (Object e : o) { celda = fila.createCell((short) i); if (i <= 6) { if (e != null) { texto = new HSSFRichTextString((String) e.toString()); } else { texto = new HSSFRichTextString(""); } celda.setCellValue(texto); } i++; } nr++; } // Se salva el libro. try { FileOutputStream elFichero = new FileOutputStream(path); libro.write(elFichero); elFichero.close(); } catch (Exception e) { e.printStackTrace(); } return true; }
From source file:Controlador.ControladorCargueMasivo.java
public static HSSFWorkbook obtenerExcel(DataModel contenidoCeldas, DataModel cabecerasCeldas, String nombreHoja) {/* w ww . ja va 2 s.c o m*/ HSSFWorkbook hssfWorkbook = new HSSFWorkbook(); HSSFSheet hssfSheet = hssfWorkbook.createSheet(nombreHoja); int numeroFila = 0; int numeroColumna = 0; HSSFRow hssfRow = hssfSheet.createRow(numeroFila++); HSSFCellStyle hssfCellStyleCabecera = hssfWorkbook.createCellStyle(); hssfCellStyleCabecera.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); hssfCellStyleCabecera.setFillBackgroundColor(new HSSFColor.BLACK().getIndex()); HSSFFont hssfFont = hssfWorkbook.createFont(); hssfFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); hssfFont.setColor(HSSFColor.WHITE.index); hssfCellStyleCabecera.setFont(hssfFont); String columnaCabecera; HSSFCell hssfCell = null; List cabecerasExcel = (List) cabecerasCeldas.getWrappedData(); for (int i = 0; i < cabecerasExcel.size(); i++) { columnaCabecera = (String) cabecerasExcel.get(i); hssfCell = hssfRow.createCell((short) numeroColumna++); hssfCell.setCellValue(columnaCabecera); hssfCell.setCellStyle(hssfCellStyleCabecera); } List contenidoExcel = (List) contenidoCeldas.getWrappedData(); List fila = null; Object valor; for (int i = 0; i < contenidoExcel.size(); i++) { fila = (List) contenidoExcel.get(i); hssfRow = hssfSheet.createRow(numeroFila++); numeroColumna = 0; for (int x = 0; x < fila.size(); x++) { valor = fila.get(x); hssfCell = hssfRow.createCell((short) numeroColumna++); hssfCell.setCellValue((String) valor); } } return hssfWorkbook; }
From source file:Controlador.jControlador.java
public boolean imprimirExcel(File archivo, JTable table) { try {/*from w w w . j a va2 s.c o m*/ HSSFWorkbook libro = new HSSFWorkbook(); HSSFSheet hoja = libro.createSheet(); for (int i = 0; i <= table.getRowCount(); i++) { HSSFRow fila = hoja.createRow(i); if (i == 0) { for (int j = 0; j < table.getColumnCount(); j++) { HSSFCell celda = fila.createCell(j); celda.setCellValue(new HSSFRichTextString( table.getColumnModel().getColumn(j).getHeaderValue().toString())); } } if (i != 0) { for (int j = 0; j < table.getColumnCount(); j++) { HSSFCell celda = fila.createCell(j); if (table.getValueAt(i - 1, j) != null) celda.setCellValue(new HSSFRichTextString(table.getValueAt(i - 1, j).toString())); } } } FileOutputStream elFichero = new FileOutputStream(archivo.getAbsolutePath() + ".xls"); libro.write(elFichero); elFichero.close(); return true; } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:corner.orm.tapestry.service.excel.ExcelService.java
License:Apache License
/** * exceltitle// w w w . ja v a 2 s . c o m * * @param wb * @param row * @param index * @param cellValue */ protected void createTitleCell(HSSFWorkbook wb, HSSFRow row, int index, String cellValue) { HSSFCell titlecell = row.createCell((short) index); if (titlecell.getCellStyle() == null) //?????? titlecell.setCellStyle(this.getTitleStyle(wb)); titlecell.setCellValue(new HSSFRichTextString(cellValue)); }
From source file:corner.orm.tapestry.service.excel.ExcelService.java
License:Apache License
/** * excelcontent/*from ww w .j a v a 2 s . co m*/ * * @param wb * @param row * @param index * @param cellValue */ protected void createContentCell(HSSFWorkbook wb, HSSFRow row, int index, String cellValue) { HSSFCell contentcell = row.createCell((short) index); if (contentcell.getCellStyle() == null) //?????? contentcell.setCellStyle(this.getContentCellStyle(wb)); contentcell.setCellValue(new HSSFRichTextString(cellValue)); }
From source file:cuenta.CuentaAhorros.java
@Override public void toExcel() { HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet(); HSSFRow row = sheet.createRow(0);/*from w w w . ja va2 s. c o m*/ HSSFCell cell = row.createCell(0); cell.setCellValue(this.toString()); try { OutputStream out = new FileOutputStream("CuentaAhorros.xls"); workbook.write(out); out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } System.out.println("Se gener el documento EXCEL de la CUENTA DE AHORROS en la raz del proyecto"); }