List of usage examples for org.apache.poi.hssf.usermodel HSSFWorkbook HSSFWorkbook
public HSSFWorkbook()
From source file:co.turnus.analysis.data.pipelining.io.XlsSimplePipeliningDataWriter.java
License:Open Source License
public void write(SimplePipelingData report, File file) { try {// w ww. j a v a 2 s . com HSSFWorkbook workbook = new HSSFWorkbook(); titleFont = workbook.createFont(); titleFont.setFontName("Arial"); titleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); cellStyle = workbook.createCellStyle(); cellStyle.setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat("m/d/yy h:mm")); HSSFSheet sheet = workbook.createSheet("Pipelinable <Actor, Action>"); // Action Actor Class Results Cell cell = sheet.createRow(0).createCell(0); HSSFRichTextString title = new HSSFRichTextString("Action and Actor Pipelining Results"); title.applyFont(titleFont); cell.setCellValue(title); Row row = sheet.createRow(1); sheet.addMergedRegion(new CellRangeAddress(1, 3, 0, 0)); row.createCell(0).setCellValue("Actor"); sheet.addMergedRegion(new CellRangeAddress(1, 3, 1, 1)); row.createCell(1).setCellValue("Action"); sheet.addMergedRegion(new CellRangeAddress(1, 3, 2, 2)); row.createCell(2).setCellValue("pipelinable"); sheet.addMergedRegion(new CellRangeAddress(1, 1, 3, 10)); row.createCell(3).setCellValue("Consecutive Executions"); sheet.addMergedRegion(new CellRangeAddress(1, 3, 11, 11)); row.createCell(11).setCellValue("Splittable Actions"); row = sheet.createRow(2); sheet.addMergedRegion(new CellRangeAddress(2, 2, 3, 6)); row.createCell(3).setCellValue("Pipelinable"); sheet.addMergedRegion(new CellRangeAddress(2, 2, 7, 10)); row.createCell(7).setCellValue("Unconstrained"); row = sheet.createRow(3); row.createCell(3).setCellValue("min"); row.createCell(4).setCellValue("mean"); row.createCell(5).setCellValue("max"); row.createCell(6).setCellValue("var"); row.createCell(7).setCellValue("min"); row.createCell(8).setCellValue("mean"); row.createCell(9).setCellValue("max"); row.createCell(10).setCellValue("var"); int rowId = 4; Map<Actor, Map<Action, SimpleActionPipeliningData>> table = report.asTable().rowMap(); for (Map<Action, SimpleActionPipeliningData> ac : table.values()) { for (SimpleActionPipeliningData data : ac.values()) { row = sheet.createRow(rowId); row.createCell(0).setCellValue(data.getActor().getId()); row.createCell(1).setCellValue(data.getAction().getId()); row.createCell(2).setCellValue(data.isPipelinable()); StatisticalData stat = data.getPipelinableRepetitions(); if (stat.getSamples() > 0) { row.createCell(3).setCellValue(stat.getMin()); row.createCell(4).setCellValue(stat.getMean()); row.createCell(5).setCellValue(stat.getMax()); row.createCell(6).setCellValue(stat.getVariance()); } else { row.createCell(3).setCellValue("-"); row.createCell(4).setCellValue("-"); row.createCell(5).setCellValue("-"); row.createCell(6).setCellValue("-"); } stat = data.getUnconstrainedRepetitions(); if (stat.getSamples() > 0) { row.createCell(7).setCellValue(stat.getMin()); row.createCell(8).setCellValue(stat.getMean()); row.createCell(9).setCellValue(stat.getMax()); row.createCell(10).setCellValue(stat.getVariance()); } else { row.createCell(7).setCellValue("-"); row.createCell(8).setCellValue("-"); row.createCell(9).setCellValue("-"); row.createCell(10).setCellValue("-"); } StringBuffer b = new StringBuffer(); for (Action action : data.getSplittableActions()) { b.append(action.getId()).append(" "); } row.createCell(11).setCellValue(b.toString()); rowId++; } } OutputStream out = new FileOutputStream(file); out = new BufferedOutputStream(out); workbook.write(out); out.close(); } catch (Exception e) { throw new TurnusRuntimeException("Error writing the excel file " + file, e.getCause()); } }
From source file:co.turnus.profiling.io.XlsHalsteadAnalysisWriter.java
License:Open Source License
public void write(SourceCodeData report, File file) { try {//w w w . j av a 2s. c om HSSFWorkbook workbook = new HSSFWorkbook(); titleFont = workbook.createFont(); titleFont.setFontName("Arial"); titleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); cellStyle = workbook.createCellStyle(); cellStyle.setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat("m/d/yy h:mm")); writeSummary(workbook, report.getNetwork(), report); writeActorClassesTable(workbook, report); OutputStream out = new FileOutputStream(file); out = new BufferedOutputStream(out); workbook.write(out); out.close(); } catch (Exception e) { throw new TurnusRuntimeException("Error writing the excel file " + file, e.getCause()); } }
From source file:co.turnus.profiling.io.XlsProfilingDataWriter.java
License:Open Source License
public void write(File file, ProfilingData data) { try {// w ww . j a v a2 s .c o m HSSFWorkbook workbook = new HSSFWorkbook(); titleFont = workbook.createFont(); titleFont.setFontName("Arial"); titleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); cellStyle = workbook.createCellStyle(); cellStyle.setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat("m/d/yy h:mm")); // writeSummary(workbook, data.getNetwork(), data); writeFifosData(workbook, data); OutputStream out = new FileOutputStream(file); out = new BufferedOutputStream(out); workbook.write(out); out.close(); } catch (Exception e) { throw new TurnusRuntimeException("Error writing the excel file " + file, e.getCause()); } }
From source file:com.aan.girsang.client.ui.master.barang.BarangPanel.java
private void exportExcel(List<Barang> dataList) throws IOException { if (dataList != null && !dataList.isEmpty()) { HSSFWorkbook workBook = new HSSFWorkbook(); HSSFSheet sheet = workBook.createSheet(); HSSFSheet worksheet = workBook.createSheet("Sheet 0"); // Nama Field Row judul = sheet.createRow((short) 0); Cell cell = judul.createCell((short) 0); cell.setCellValue("This is a test of merging"); HSSFRow headingRow = sheet.createRow((short) 2); headingRow.createCell((short) 0).setCellValue("ID"); headingRow.createCell((short) 1).setCellValue("BARCODE 1"); headingRow.createCell((short) 2).setCellValue("BARCODE 2"); headingRow.createCell((short) 3).setCellValue("NAMA BARANG"); headingRow.createCell((short) 4).setCellValue("GOLONGAN"); headingRow.createCell((short) 5).setCellValue("SAT. JUAL"); headingRow.createCell((short) 6).setCellValue("ST. TOKO"); headingRow.createCell((short) 7).setCellValue("ST. GUDANG"); headingRow.createCell((short) 8).setCellValue("SAT. BELI"); headingRow.createCell((short) 9).setCellValue("ISI PEM."); headingRow.createCell((short) 10).setCellValue("HRG PEM."); headingRow.createCell((short) 11).setCellValue("HRG NORMAL"); headingRow.createCell((short) 12).setCellValue("HRG MEMBER"); headingRow.createCell((short) 13).setCellValue("JUAL"); int panjang = headingRow.getLastCellNum() - 1; short rowNo = 3; sheet.addMergedRegion(new CellRangeAddress(0, //first row (0-based) 0, //last row (0-based) 0, //first column (0-based) panjang //last column (0-based) ));/* w w w.j a v a2 s . c o m*/ CellStyle styleData = workBook.createCellStyle(); styleData.setBorderBottom(CellStyle.BORDER_THIN); styleData.setBorderRight(CellStyle.BORDER_THIN); styleData.setBorderLeft(CellStyle.BORDER_THIN); for (Barang b : dataList) { HSSFRow row = sheet.createRow(rowNo); String jual; if (b.getJual() == true) { jual = "Jual"; } else { jual = "Tidak"; } row.createCell((short) 0).setCellValue(b.getPlu()); row.createCell((short) 1).setCellValue(b.getBarcode1()); row.createCell((short) 2).setCellValue(b.getBarcode2()); row.createCell((short) 3).setCellValue(b.getNamaBarang()); row.createCell((short) 4).setCellValue(b.getGolonganBarang().getGolonganBarang()); row.createCell((short) 5).setCellValue(b.getSatuan()); row.createCell((short) 6).setCellValue(b.getStokToko()); row.createCell((short) 7).setCellValue(b.getStokGudang()); row.createCell((short) 8).setCellValue(b.getSatuanPembelian()); row.createCell((short) 9).setCellValue(b.getIsiPembelian()); row.createCell((short) 10).setCellValue(TextComponentUtils.formatNumber(b.getHargaBeli())); row.createCell((short) 11).setCellValue(TextComponentUtils.formatNumber(b.getHargaNormal())); row.createCell((short) 12).setCellValue(TextComponentUtils.formatNumber(b.getHargaMember())); row.createCell((short) 13).setCellValue(jual); for (int i = 0; i <= 13; i++) { row.getCell((short) i).setCellStyle(styleData); } rowNo++; } for (int i = 0; i <= 13; i++) { sheet.autoSizeColumn(i); } Font font = workBook.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); //style judul CellStyle styleTitle = workBook.createCellStyle(); styleTitle.setAlignment(CellStyle.ALIGN_CENTER_SELECTION); styleTitle.setFont(font); judul.getCell(0).setCellStyle(styleTitle); //judul field CellStyle styleHeading = workBook.createCellStyle(); styleHeading.setFont(font); styleHeading.setAlignment(CellStyle.ALIGN_CENTER_SELECTION); styleHeading.setBorderBottom(CellStyle.BORDER_THIN); styleHeading.setBorderTop(CellStyle.BORDER_THIN); styleHeading.setBorderRight(CellStyle.BORDER_THIN); styleHeading.setBorderLeft(CellStyle.BORDER_THIN); for (int i = 0; i < headingRow.getLastCellNum(); i++) {//For each cell in the row headingRow.getCell(i).setCellStyle(styleHeading);//Set the style } String file = "D:/Student_detais.xls"; try { try (FileOutputStream fos = new FileOutputStream(file)) { workBook.write(fos); } JOptionPane.showMessageDialog(null, "Sukses"); } catch (FileNotFoundException e) { System.out.println("Invalid directory or file not found"); } catch (IOException e) { System.out.println("Error occurred while writting excel file to directory"); } } }
From source file:com.admin.poi.ExcelUtils.java
License:Apache License
/** * excel/*www . java2 s .co m*/ * * @param excelSheet sheet ? * @param fileType * @param outputStream ? */ private static void export(ExcelSheet excelSheet, ExcelSheet.ExcelType fileType, OutputStream outputStream) throws IllegalAccessException, IOException, InvocationTargetException { Assert.notNull(fileType, "?"); Assert.notNull(outputStream, "? null"); Workbook workbook; if (fileType == ExcelSheet.ExcelType.XLS) { workbook = new HSSFWorkbook(); } else if (fileType == ExcelSheet.ExcelType.XLSX) { workbook = new XSSFWorkbook(); } else { throw new IllegalArgumentException("???"); } export(excelSheet, workbook, outputStream); }
From source file:com.adonis.ui.print.PrintVehiclesUI.java
public static File createXLSVehicles(String fileName, List<Vehicle> vehicles) { try {//from ww w .j ava 2 s .c om HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("Excel Sheet"); HSSFRow rowhead = sheet.createRow((short) 0); rowhead.createCell((short) 0).setCellValue("vehicleNmbr"); rowhead.createCell((short) 1).setCellValue("licenseNmbr"); rowhead.createCell((short) 2).setCellValue("make"); rowhead.createCell((short) 3).setCellValue("vehicleType"); rowhead.createCell((short) 4).setCellValue("model"); rowhead.createCell((short) 5).setCellValue("price"); rowhead.createCell((short) 6).setCellValue("location"); vehicles.forEach(rent -> { HSSFRow row = sheet.createRow((short) index); row.createCell((short) 0).setCellValue(rent.getVehicleNmbr()); row.createCell((short) 1).setCellValue(rent.getLicenseNmbr()); row.createCell((short) 2).setCellValue(rent.getMake()); row.createCell((short) 3).setCellValue(rent.getVehicleType()); row.createCell((short) 4).setCellValue(rent.getModel()); row.createCell((short) 5).setCellValue(rent.getPrice()); row.createCell((short) 6).setCellValue(rent.getLocation()); index++; }); FileOutputStream fileOut = new FileOutputStream(fileName); wb.write(fileOut); fileOut.close(); System.out.println("Data is saved in excel file."); } catch (Exception ex) { ex.printStackTrace(); } return new File(fileName); }
From source file:com.ah.ui.actions.admin.LicenseMgrAction.java
License:Open Source License
private void exportEntitleKeyInfo() { try {/*from ww w.j av a2s . c o m*/ // create a new file FileOutputStream out = new FileOutputStream(ORDERKEYINFO_EXPORT_FILE_PATH); // create a new workbook HSSFWorkbook wb = new HSSFWorkbook(); // create a new sheet HSSFSheet s = wb.createSheet("Sheet1"); // declare a row object reference HSSFRow r = null; // declare a cell object reference HSSFCell c = null; // row index int rowNum = 0; // cell count int cellcount = 0; if (NmsUtil.isHMForOEM()) { cellcount = 7; } else if (getIsInHomeDomain()) { cellcount = 8; } else if (NmsUtil.isHostedHMApplication()) { cellcount = 9; } if (cellcount == 0) { return; } else { for (int i = 0; i < cellcount; i++) { s.setColumnWidth(i, getColumnWidthByIndex(i) * 256); } } // create cell style HSSFCellStyle cs = wb.createCellStyle(); // create font object HSSFFont f = wb.createFont(); //set font to 12 point type f.setFontHeightInPoints((short) 12); f.setFontName("Calibri"); //set cell stlye cs.setFont(f); cs.setAlignment(CellStyle.ALIGN_CENTER); cs.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); // create cell style HSSFCellStyle cs1 = wb.createCellStyle(); // create font object HSSFFont f1 = wb.createFont(); //set font to 12 point type f1.setFontHeightInPoints((short) 12); f1.setFontName("Calibri"); f1.setBoldweight(Font.BOLDWEIGHT_BOLD); //set cell stlye cs1.setFont(f1); cs1.setAlignment(CellStyle.ALIGN_RIGHT); cs1.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); // create cell style HSSFCellStyle cs2 = wb.createCellStyle(); cs2.setFont(f1); cs2.setAlignment(CellStyle.ALIGN_CENTER); cs2.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); // create cell style HSSFCellStyle cs3 = wb.createCellStyle(); cs3.setFont(f); cs3.setAlignment(CellStyle.ALIGN_RIGHT); cs3.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); // create cell style HSSFCellStyle cs4 = wb.createCellStyle(); cs4.setFont(f1); cs4.setAlignment(CellStyle.ALIGN_LEFT); cs4.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); // create cell style HSSFCellStyle cs5 = wb.createCellStyle(); // create font object HSSFFont f2 = wb.createFont(); //set font to 12 point type f2.setFontHeightInPoints((short) 12); f2.setFontName("Calibri"); f2.setBoldweight(Font.BOLDWEIGHT_BOLD); f2.setColor(Font.COLOR_RED); cs5.setFont(f2); cs5.setAlignment(CellStyle.ALIGN_LEFT); cs5.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); // create cell style HSSFCellStyle cs6 = wb.createCellStyle(); cs6.setFont(f); cs6.setAlignment(CellStyle.ALIGN_LEFT); cs6.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); // create a row // row 1 s.addMergedRegion(new CellRangeAddress(0, 0, 0, cellcount - 1)); r = s.createRow(rowNum++); c = r.createCell(0); c.setCellValue(MgrUtil.getUserMessage("admin.license.orderkey.export.title")); c.setCellStyle(cs); // row 2 String sysInfo = ""; if (getIsInHomeDomain()) { sysInfo = "System ID: " + getSystemId(); // HiveManager Online user } else if (NmsUtil.isHostedHMApplication()) { sysInfo = "VHM ID: " + getDomain().getVhmID(); } s.addMergedRegion(new CellRangeAddress(1, 1, 0, cellcount - 1)); r = s.createRow(rowNum++); c = r.createCell(0); c.setCellValue(sysInfo); c.setCellStyle(cs); // row 3 s.addMergedRegion(new CellRangeAddress(2, 2, 0, cellcount - 1)); r = s.createRow(rowNum++); c = r.createCell(0); List<?> userInfo = QueryUtil.executeQuery( "SELECT email, company FROM " + UserRegInfoForLs.class.getSimpleName(), null, new FilterParams("owner.domainName", getDomain().getDomainName())); if (!userInfo.isEmpty()) { Object[] userInfos = (Object[]) userInfo.get(0); c.setCellValue(MgrUtil.getUserMessage("admin.license.orderkey.export.email.company", new String[] { (String) userInfos[0], (String) userInfos[1] })); } c.setCellStyle(cs); // row 4 r = s.createRow(rowNum++); // row 5 r = s.createRow(rowNum++); // row 6 cell 1 c = r.createCell(0); c.setCellValue(MgrUtil.getUserMessage("admin.license.orderkey.export.device.licensed")); c.setCellStyle(cs1); // row 6 cell 2 c = r.createCell(1); c.setCellValue(licenseInfo.getHiveAps()); c.setCellStyle(cs2); // device management info Map<String, Integer> apcount = HiveAPInfoFromeDatabase .getManagedDeviceTypeAndNumber(getDomain().getDomainName()); int vpnCount = 0; int totalCount = 0; if (null != apcount) { Object[] typeNames = apcount.keySet().toArray(); Arrays.sort(typeNames); for (Object typeName : typeNames) { // VPN Gateway VA does not belong to device if (MgrUtil.getEnumString("enum.hiveAp.model.10").equals(typeName)) { vpnCount = apcount.get(typeName); } else { r = s.createRow(rowNum++); c = r.createCell(0); c.setCellValue((String) typeName); c.setCellStyle(cs3); c = r.createCell(1); c.setCellValue(apcount.get(typeName)); c.setCellStyle(cs); totalCount += apcount.get(typeName); } } } // managed device total number cell1 r = s.createRow(rowNum++); c = r.createCell(0); c.setCellValue(MgrUtil.getUserMessage("admin.license.orderkey.export.device.total")); c.setCellStyle(cs1); // managed device total number cell2 c = r.createCell(1); c.setCellValue(totalCount); c.setCellStyle(cs2); // blank row r = s.createRow(rowNum++); // licensed VPN Gateway VA cell1 r = s.createRow(rowNum++); c = r.createCell(0); c.setCellValue(MgrUtil.getUserMessage("admin.license.orderkey.export.cvg.licensed")); c.setCellStyle(cs1); // licensed VPN Gateway VA cell2 c = r.createCell(1); c.setCellValue(licenseInfo.getCvgNumber()); c.setCellStyle(cs2); // managed VPN Gateway VA cell1 r = s.createRow(rowNum++); c = r.createCell(0); c.setCellValue(MgrUtil.getUserMessage("admin.license.orderkey.export.cvg.total")); c.setCellStyle(cs1); // managed VPN Gateway VA cell 2 c = r.createCell(1); c.setCellValue(vpnCount); c.setCellStyle(cs2); // entitlement key information preparePage(); if (null != page && !page.isEmpty()) { r = s.createRow(rowNum++); List<OrderHistoryInfo> normalKey = new ArrayList<>(); List<OrderHistoryInfo> invalidKey = new ArrayList<>(); List<OrderHistoryInfo> expiredKey = new ArrayList<>(); for (Object obj : page) { OrderHistoryInfo orderInfo = (OrderHistoryInfo) obj; if (orderInfo.getStatusFlag() == OrderHistoryInfo.ENTITLE_KEY_STATUS_NORMAL && orderInfo.getCvgStatusFlag() == OrderHistoryInfo.ENTITLE_KEY_STATUS_NORMAL) { normalKey.add(orderInfo); } else if (orderInfo.getStatusFlag() == OrderHistoryInfo.ENTITLE_KEY_STATUS_DISABLE || orderInfo.getCvgStatusFlag() == OrderHistoryInfo.ENTITLE_KEY_STATUS_DISABLE) { invalidKey.add(orderInfo); } else { expiredKey.add(orderInfo); } } if (!normalKey.isEmpty()) { // normal entitle key title r = s.createRow(rowNum++); setEntitlementKeyCellValue(cellcount, cs4, null, r, null, MgrUtil.getUserMessage("order.key")); // normal entitle key info for (OrderHistoryInfo keyInfo : normalKey) { r = s.createRow(rowNum++); setEntitlementKeyCellValue(cellcount, cs6, cs3, r, keyInfo, null); } } if (!invalidKey.isEmpty()) { if (!normalKey.isEmpty()) { r = s.createRow(rowNum++); r = s.createRow(rowNum++); } // invalid entitle key title r = s.createRow(rowNum++); setEntitlementKeyCellValue(cellcount, cs5, null, r, null, MgrUtil.getUserMessage("admin.license.orderkey.export.invalidkey.title")); // invalid entitle key info for (OrderHistoryInfo keyInfo : invalidKey) { r = s.createRow(rowNum++); setEntitlementKeyCellValue(cellcount, cs6, cs3, r, keyInfo, null); } } if (!expiredKey.isEmpty()) { if (!normalKey.isEmpty() || !invalidKey.isEmpty()) { r = s.createRow(rowNum++); r = s.createRow(rowNum++); } // expired entitle key title r = s.createRow(rowNum++); setEntitlementKeyCellValue(cellcount, cs5, null, r, null, MgrUtil.getUserMessage("admin.license.orderkey.export.expiredkey.title")); // expired entitle key info for (OrderHistoryInfo keyInfo : expiredKey) { r = s.createRow(rowNum++); setEntitlementKeyCellValue(cellcount, cs6, cs3, r, keyInfo, null); } } } // write the workbook to the output stream // close our file (don't blow out our file handles) wb.write(out); out.close(); generateAuditLog(HmAuditLog.STATUS_SUCCESS, MgrUtil.getUserMessage("hm.audit.log.export.entitlement.key")); } catch (Exception ex) { generateAuditLog(HmAuditLog.STATUS_FAILURE, MgrUtil.getUserMessage("hm.audit.log.export.entitlement.key")); log.error("exportEntitleKeyInfo()", ex.getMessage()); } }
From source file:com.aimluck.eip.modules.screens.ALXlsScreen.java
License:Open Source License
/** * xls?????/*ww w . ja va 2s .co m*/ * * @param rundata */ protected HSSFWorkbook createXLSFile(RunData rundata, Context context) { try { HSSFWorkbook wb = new HSSFWorkbook(); createHSSFWorkbook(rundata, context, wb); return wb; } catch (Exception e) { logger.error("ALXlsScreen.createXLSFile", e); return null; } }
From source file:com.alibaba.differ.biz.TableExporter.java
License:Open Source License
public void export() throws IOException { fc.setFileFilter(new ExcelFileFilter()); fc.setFileHidingEnabled(true);/*from w ww . j ava 2s . c o m*/ fc.setAcceptAllFileFilterUsed(false); int returnValue = fc.showSaveDialog(null); if (returnValue != JFileChooser.APPROVE_OPTION) { return; } File file = fc.getSelectedFile(); if (file.exists()) { JOptionPane.showMessageDialog(null, ""); return; } FileOutputStream fos = new FileOutputStream(file + ".xls"); HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet hs = wb.createSheet(); TableModel tm = table.getModel(); int row = tm.getRowCount(); int cloumn = tm.getColumnCount(); HSSFCellStyle style = wb.createCellStyle(); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); style.setBorderRight(HSSFCellStyle.BORDER_THIN); style.setBorderTop(HSSFCellStyle.BORDER_THIN); style.setFillForegroundColor(HSSFColor.LIGHT_GREEN.index); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); HSSFFont font = wb.createFont(); font.setFontHeightInPoints((short) 11); style.setFont(font); HSSFCellStyle style1 = wb.createCellStyle(); style1.setBorderBottom(HSSFCellStyle.BORDER_THIN); style1.setBorderLeft(HSSFCellStyle.BORDER_THIN); style1.setBorderRight(HSSFCellStyle.BORDER_THIN); style1.setBorderTop(HSSFCellStyle.BORDER_THIN); style1.setFillForegroundColor(HSSFColor.ORANGE.index); style1.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); HSSFFont font1 = wb.createFont(); font1.setFontHeightInPoints((short) 15); font1.setBoldweight((short) 700); style1.setFont(font); for (int i = 0; i < row + 1; i++) { HSSFRow hr = hs.createRow(i); for (int j = 0; j < cloumn; j++) { if (i == 0) { String value = tm.getColumnName(j); hs.setColumnWidth(j, UIConfig.EXCEL_COLUMN_WIDTH); HSSFRichTextString srts = new HSSFRichTextString(value); HSSFCell hc = hr.createCell((short) j); hc.setCellStyle(style1); hc.setCellValue(srts); } else { if (tm.getValueAt(i - 1, j) != null) { String value = tm.getValueAt(i - 1, j).toString(); HSSFRichTextString srts = new HSSFRichTextString(value); HSSFCell hc = hr.createCell((short) j); hc.setCellStyle(style); if (value.equals("") || value == null) { hc.setCellValue(new HSSFRichTextString("")); } else { hc.setCellValue(srts); } } } } } wb.write(fos); fos.close(); JOptionPane.showMessageDialog(null, "Excel"); }
From source file:com.alibaba.stonelab.webxsample.sample.web.module.screen.Download.java
License:Open Source License
private Workbook getWorkbook() { Workbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet("gift"); Row row = sheet.createRow(0);/*from www . j a v a 2 s . c o m*/ row.createCell(0).setCellValue("id"); row.createCell(1).setCellValue("name"); for (int i = 1; i <= 10; i++) { Row r = sheet.createRow(i); r.createCell(0).setCellValue(i); r.createCell(1).setCellValue("name" + i); } return wb; }