List of usage examples for org.apache.poi.xssf.usermodel XSSFFont setFontHeightInPoints
public void setFontHeightInPoints(short height)
From source file:br.com.jinsync.controller.ExportExcelBook.java
License:Open Source License
@Override protected Object doInBackground() throws Exception { final String dir = System.getProperty("user.dir") + "\\layouts"; File arqProp = new File(dir); if (!arqProp.exists()) { arqProp.mkdirs();//from w w w . j a v a 2 s. c om } String nameFile = this.nameFile; int lin = 0; int col = 0; int pos = 0; int posFim = 0; pos = nameFile.lastIndexOf("("); if (pos > 0) { posFim = nameFile.lastIndexOf(")"); nameFile = dir + "\\" + nameFile.substring(pos + 1, posFim) + "_layout" + ".xlsx"; } else { pos = nameFile.lastIndexOf("\\"); if (pos > 0) { posFim = nameFile.lastIndexOf("."); if (posFim > 0) { nameFile = dir + "\\" + nameFile.substring(pos + 1, posFim) + "_layout" + ".xlsx"; } else { nameFile = dir + nameFile.substring(pos) + "_layout" + ".xlsx"; } } } FileOutputStream out; try { out = new FileOutputStream(nameFile); TableModel model = tableName.getModel(); XSSFWorkbook wb = new XSSFWorkbook(); // Criando area de trabalho // para o excel XSSFSheet s = wb.createSheet(); // criando uma nova sheet XSSFFont f = wb.createFont(); XSSFFont f2 = wb.createFont(); XSSFCellStyle cs = wb.createCellStyle(); XSSFCellStyle cs2 = wb.createCellStyle(); XSSFCellStyle cs3 = wb.createCellStyle(); XSSFCellStyle cs4 = wb.createCellStyle(); f.setFontHeightInPoints((short) 8); f2.setFontHeightInPoints((short) 8); f.setBoldweight(Font.BOLDWEIGHT_BOLD); f2.setBoldweight(Font.BOLDWEIGHT_NORMAL); f.setFontName("Courier New"); f2.setFontName("Courier New"); XSSFRow r = null; // Criando uma referencia para Linha XSSFCell c = null; // Referencia para Celula cs.setFont(f); cs2.setFont(f2); cs3.setFont(f2); cs4.setFont(f); cs2.setAlignment(CellStyle.ALIGN_LEFT); cs3.setAlignment(CellStyle.ALIGN_RIGHT); cs4.setAlignment(CellStyle.ALIGN_RIGHT); r = s.createRow(lin); for (int i = 1; i < model.getColumnCount(); i++) { c = r.createCell(col); c.setCellStyle(cs); c.setCellValue(model.getColumnName(i)); col = col + 1; } col = 0; for (int i = 0; i < model.getRowCount(); i++) { lin = lin + 1; r = s.createRow(lin); col = 0; for (int j = 1; j < model.getColumnCount(); j++) { String valor = model.getValueAt(i, j).toString(); if (valor == null) { valor = ""; } c = r.createCell(col); c.setCellStyle(cs2); if (valor.matches("-?\\d+(\\.\\d+)?")) { c.setCellValue(Double.parseDouble(valor)); c.setCellType(Cell.CELL_TYPE_NUMERIC); c.setCellStyle(cs4); } else { c.setCellValue(valor); } col = col + 1; } } for (int i = 0; i <= model.getColumnCount(); i++) { s.autoSizeColumn(i); } wb.write(out); wb.close(); out.close(); Desktop desktop = Desktop.getDesktop(); desktop.open(new File(nameFile)); } catch (FileNotFoundException e) { JOptionPane.showMessageDialog(null, e.getLocalizedMessage()); e.printStackTrace(); } catch (IOException e) { JOptionPane.showMessageDialog(null, e.getLocalizedMessage()); e.printStackTrace(); } return null; }
From source file:br.com.jinsync.controller.ExportExcelFile.java
License:Open Source License
@Override protected Object doInBackground() throws Exception { int valuePgsBar = 0; int qtdTotLin = 0; final String dir = System.getProperty("user.dir") + "\\file"; File arqProp = new File(dir); if (!arqProp.exists()) { arqProp.mkdirs();/* www .j a v a 2s .c o m*/ } String nameFile = name; int lin = 0; int col = 0; int pos = 0; int posEnd = 0; pos = nameFile.lastIndexOf("("); if (pos > 0) { posEnd = nameFile.lastIndexOf(")"); nameFile = dir + "\\" + nameFile.substring(pos + 1, posEnd) + "_file" + ".xlsx"; } else { pos = nameFile.lastIndexOf("\\"); if (pos > 0) { posEnd = nameFile.lastIndexOf("."); if (posEnd > 0) { nameFile = dir + "\\" + nameFile.substring(pos + 1, posEnd) + "_file" + ".xlsx"; } else { nameFile = dir + nameFile.substring(pos) + "_file" + ".xlsx"; } } } FileOutputStream out; try { out = new FileOutputStream(nameFile); TableModel model = tableName.getModel(); XSSFWorkbook wb = new XSSFWorkbook(); // Criando area de trabalho // para o excel XSSFSheet s = wb.createSheet(); // criando uma nova sheet XSSFFont f = wb.createFont(); XSSFFont f2 = wb.createFont(); XSSFCellStyle cs = wb.createCellStyle(); XSSFCellStyle cs2 = wb.createCellStyle(); XSSFCellStyle cs3 = wb.createCellStyle(); XSSFCellStyle cs4 = wb.createCellStyle(); f.setFontHeightInPoints((short) 8); f2.setFontHeightInPoints((short) 8); f.setBoldweight(Font.BOLDWEIGHT_BOLD); f2.setBoldweight(Font.BOLDWEIGHT_NORMAL); f.setFontName("Courier New"); f2.setFontName("Courier New"); XSSFRow r = null; // Criando uma referencia para Linha XSSFCell c = null; // Referencia para Celula cs.setFont(f); cs2.setFont(f2); cs3.setFont(f2); cs4.setFont(f2); cs2.setAlignment(CellStyle.ALIGN_LEFT); cs3.setAlignment(CellStyle.ALIGN_RIGHT); cs4.setAlignment(CellStyle.ALIGN_RIGHT); r = s.createRow(lin); for (int i = 1; i < model.getColumnCount(); i++) { c = r.createCell(col); c.setCellStyle(cs); c.setCellValue(model.getColumnName(i)); col = col + 1; } col = 0; qtdTotLin = model.getRowCount() - 1; if (qtdTotLin == 0) { qtdTotLin = 1; } for (int i = 0; i < model.getRowCount(); i++) { valuePgsBar = (i * 100) / qtdTotLin; lin = lin + 1; r = s.createRow(lin); col = 0; for (int j = 1; j < model.getColumnCount(); j++) { String valor = model.getValueAt(i, j).toString(); if (valor == null) { valor = ""; } c = r.createCell(col); c.setCellStyle(cs2); valor = valor.trim(); if (valor.matches("-?\\d+(\\.\\d+)?")) { c.setCellValue(Double.parseDouble(valor)); c.setCellType(Cell.CELL_TYPE_NUMERIC); c.setCellStyle(cs4); } else { c.setCellValue(valor); } col = col + 1; setProgress(valuePgsBar); } } for (int i = 0; i <= model.getColumnCount(); i++) { s.autoSizeColumn(i); } wb.write(out); wb.close(); out.close(); Desktop desktop = Desktop.getDesktop(); desktop.open(new File(nameFile)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block JOptionPane.showMessageDialog(null, e.getLocalizedMessage()); e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block JOptionPane.showMessageDialog(null, e.getLocalizedMessage()); e.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:br.com.jinsync.controller.ExportExcelString.java
License:Open Source License
@Override protected Object doInBackground() throws Exception { final String dir = System.getProperty("user.dir") + "\\string"; File arqProp = new File(dir); if (!arqProp.exists()) { arqProp.mkdirs();//from w ww. ja va 2 s . c o m } String nameFile = this.nameFile; int lin = 0; int col = 0; int pos = 0; int posFim = 0; int valDec = 0; pos = nameFile.lastIndexOf("("); if (pos > 0) { posFim = nameFile.lastIndexOf(")"); nameFile = dir + "\\" + nameFile.substring(pos + 1, posFim) + "_string" + ".xlsx"; } else { pos = nameFile.lastIndexOf("\\"); if (pos > 0) { posFim = nameFile.lastIndexOf("."); if (posFim > 0) { nameFile = dir + "\\" + nameFile.substring(pos + 1, posFim) + "_string" + ".xlsx"; } else { nameFile = dir + nameFile.substring(pos) + "_string" + ".xlsx"; } } } FileOutputStream out; try { out = new FileOutputStream(nameFile); TableModel model = tableName.getModel(); XSSFWorkbook wb = new XSSFWorkbook(); // Criando area de trabalho // para o excel XSSFSheet s = wb.createSheet(); // criando uma nova sheet XSSFFont f = wb.createFont(); XSSFFont f2 = wb.createFont(); XSSFCellStyle cs = wb.createCellStyle(); XSSFCellStyle cs2 = wb.createCellStyle(); XSSFCellStyle cs3 = wb.createCellStyle(); XSSFCellStyle cs4 = wb.createCellStyle(); f.setFontHeightInPoints((short) 8); f2.setFontHeightInPoints((short) 8); f.setBoldweight(Font.BOLDWEIGHT_BOLD); f2.setBoldweight(Font.BOLDWEIGHT_NORMAL); f.setFontName("Courier New"); f2.setFontName("Courier New"); XSSFRow r = null; // Criando uma referencia para Linha XSSFCell c = null; // Referencia para Celula cs.setFont(f); cs2.setFont(f2); cs3.setFont(f2); cs4.setFont(f); cs2.setAlignment(CellStyle.ALIGN_LEFT); cs3.setAlignment(CellStyle.ALIGN_RIGHT); cs4.setAlignment(CellStyle.ALIGN_RIGHT); r = s.createRow(lin); r = s.createRow(0); // Criando a primeira linha na LINHA zero, que // seria o nmero 1 c = r.createCell(0); // Criando a celula na posicao ZERO, que seria // A, com referencia na linha zero acima = // A1 c.setCellStyle(cs); c.setCellValue(Language.stringFieldName); c = r.createCell(1); c.setCellStyle(cs); c.setCellValue(Language.stringType); c = r.createCell(2); c.setCellStyle(cs); c.setCellValue(Language.stringLength); c = r.createCell(3); c.setCellStyle(cs); c.setCellValue(Language.stringDecimal); c = r.createCell(4); c.setCellStyle(cs); c.setCellValue(Language.stringTotal); c = r.createCell(5); c.setCellStyle(cs4); c.setCellValue(Language.stringContent); col = 0; lin = lin + 1; for (int i = 0; i < model.getColumnCount(); i++) { r = s.createRow(lin); c = r.createCell(col); c.setCellStyle(cs2); c.setCellValue(model.getColumnName(i)); col = col + 1; c = r.createCell(col); c.setCellStyle(cs2); c.setCellValue(tipoConteudo.get(i)); col = col + 1; c = r.createCell(col); c.setCellStyle(cs2); if (tamanhoConteudo.get(i).matches("-?\\d+(\\.\\d+)?")) { c.setCellValue(Double.parseDouble(tamanhoConteudo.get(i))); c.setCellType(Cell.CELL_TYPE_NUMERIC); c.setCellStyle(cs3); } else { c.setCellValue(tamanhoConteudo.get(i)); } col = col + 1; c = r.createCell(col); c.setCellStyle(cs2); if (decimalConteudo.get(i).matches("-?\\d+(\\.\\d+)?")) { c.setCellValue(Integer.parseInt(decimalConteudo.get(i))); valDec = Integer.parseInt(decimalConteudo.get(i)); c.setCellType(Cell.CELL_TYPE_NUMERIC); c.setCellStyle(cs3); } else { c.setCellValue(decimalConteudo.get(i)); valDec = 0; } col = col + 1; c = r.createCell(col); c.setCellStyle(cs2); c.setCellValue(totalConteudo.get(i)); col = col + 1; c = r.createCell(col); c.setCellStyle(cs2); String valor = model.getValueAt(0, i).toString().trim(); if (valor == null) { valor = ""; } if (valor.matches("-?\\d+(\\.\\d+)?")) { if (Double.parseDouble(valor) > 0 && valDec > 0) { double val2 = Double.parseDouble(valor) / (Math.pow(10, valDec)); NumberFormat format = NumberFormat.getInstance(); format.setMinimumFractionDigits(2); format.setMaximumFractionDigits(valDec); c.setCellValue(format.format(val2).toString()); } else { c.setCellValue(Double.parseDouble(valor)); } // c.setCellType(Cell.CELL_TYPE_NUMERIC); c.setCellStyle(cs3); } else { c.setCellValue(valor); } lin = lin + 1; col = 0; } for (int i = 0; i <= model.getColumnCount(); i++) { s.autoSizeColumn(i); } wb.write(out); wb.close(); out.close(); Desktop desktop = Desktop.getDesktop(); desktop.open(new File(nameFile)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block JOptionPane.showMessageDialog(null, e.getLocalizedMessage()); //e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block JOptionPane.showMessageDialog(null, e.getLocalizedMessage()); //e.printStackTrace(); } return null; }
From source file:com.frameworkset.platform.sanylog.common.POIExcelUtil2007.java
License:Open Source License
private static XSSFFont getBaseFont(XSSFWorkbook wb) {// XSSFFont font = wb.createFont(); font.setFontHeightInPoints((short) 12); return font;//from w w w .j av a 2 s . c om }
From source file:com.frameworkset.platform.util.POIExcelUtil.java
License:Open Source License
public static XSSFFont getBaseFont(XSSFWorkbook wb) { XSSFFont font = wb.createFont(); font.setFontHeightInPoints((short) 12); return font;/*from www . j a va 2 s . c o m*/ }
From source file:com.sec.ose.osi.report.standard.ISheetTemplate.java
License:Open Source License
/** * @param color/*w w w. j ava 2 s.co m*/ * @param size * @param bold * @return Font */ protected XSSFFont getFont(XSSFColor color, short size, boolean bold) { XSSFFont font = wb.createFont(); font.setFontHeightInPoints(size); font.setFontName("Tahoma"); font.setColor(color); if (bold) font.setBoldweight(Font.BOLDWEIGHT_BOLD); return font; }
From source file:com.sec.ose.osi.report.standard.ISheetTemplate.java
License:Open Source License
protected XSSFFont getFont(int color, short size, boolean bold) { XSSFFont font = wb.createFont(); font.setFontHeightInPoints(size); font.setFontName("Tahoma"); font.setColor((short) color); if (bold)/*from w ww .j a va 2 s . c om*/ font.setBoldweight(Font.BOLDWEIGHT_BOLD); return font; }
From source file:com.solidmaps.webapp.report.utils.ExcelMapCivilGenerator.java
private void loadStyle() { styleProductList = wb.createCellStyle(); styleProductList.setBorderRight(HSSFCellStyle.BORDER_THIN); styleProductList.setBorderLeft(HSSFCellStyle.BORDER_THIN); styleProductList.setBorderTop(HSSFCellStyle.BORDER_THIN); styleProductList.setBorderBottom(HSSFCellStyle.BORDER_THIN); styleProductList.setAlignment(XSSFCellStyle.ALIGN_CENTER); XSSFFont txtFont = wb.createFont(); txtFont.setFontName("Arial"); txtFont.setFontHeightInPoints((short) 8); styleProductList.setFont(txtFont);// w w w . jav a 2 s.c om }
From source file:DSC.AccountantReport.java
private static void createExcelReport() { XSSFWorkbook workbook = new XSSFWorkbook(); clients.sort(new Comparator<Client>() { @Override/*from w w w . ja va 2 s . c o m*/ public int compare(Client o1, Client o2) { return (o1.getSurname() + " " + o1.getName()).compareTo(o2.getSurname() + " " + o2.getName()); } }); int lastIndex = 0; for (int letter = 0; letter < 26; letter++) { XSSFSheet sheet = workbook.createSheet("AccountReport " + (char) (65 + letter)); Map<String, Object[]> data = new TreeMap<>(); data.put("1", new Object[] { "Doorstep Chef Accountant Sheet", "", "", "", "", "", "", "Week: " + DriverReport.returnWeekInt(), "", "" }); data.put("2", new Object[] { "", "", "", "", "", "", "", "", "", "" }); data.put("3", new Object[] { "Customer", "Contact", "Fam", "4Day", "Mthly", "EFT", "Cash", "Date Paid", "Stay", "Comments" }); int reduction = 0; for (int i = 0; i < clients.size(); i++) { Client client = clients.get(i); if (client.getSurname().toUpperCase().charAt(0) == (char) (65 + letter)) { data.put((i + 4 - reduction) + "", new Object[] { client.getName() + " " + client.getSurname(), client.getContactNumber().substring(0, 3) + " " + client.getContactNumber().substring(3, 6) + " " + client.getContactNumber().substring(6, 10), client.getAdditionalInfo(), "", "", "", "", "", "", "" }); } else { reduction++; } } Set<String> keySet = data.keySet(); int totalSize = 34900; int longestCustomer = 0; for (int key = 1; key < keySet.size() + 1; key++) { Row row = sheet.createRow(key - 1); Object[] arr = data.get(key + ""); for (int i = 0; i < arr.length; i++) { Cell cell = row.createCell(i); cell.setCellValue((String) arr[i]); if (i == 0 && !(key + "").equals("1") && longestCustomer < ((String) arr[i]).length()) { longestCustomer = ((String) arr[i]).length(); } XSSFCellStyle borderStyle = workbook.createCellStyle(); if (!((key + "").equals("1") || (key + "").equals("2"))) { borderStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex()); borderStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex()); borderStyle.setTopBorderColor(IndexedColors.BLACK.getIndex()); borderStyle.setRightBorderColor(IndexedColors.BLACK.getIndex()); if ((key + "").equals("3")) { borderStyle.setBorderBottom(XSSFCellStyle.BORDER_MEDIUM); borderStyle.setBorderLeft(XSSFCellStyle.BORDER_MEDIUM); borderStyle.setBorderTop(XSSFCellStyle.BORDER_MEDIUM); borderStyle.setBorderRight(XSSFCellStyle.BORDER_MEDIUM); borderStyle.setAlignment(HorizontalAlignment.CENTER); borderStyle.setFillPattern(XSSFCellStyle.LESS_DOTS); borderStyle.setFillBackgroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); XSSFFont font = workbook.createFont(); font.setColor(IndexedColors.WHITE.getIndex()); font.setBold(true); borderStyle.setFont(font); } else { if (i != 0) { borderStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN); } else { borderStyle.setBorderLeft(XSSFCellStyle.BORDER_MEDIUM); } if (i != 9) { borderStyle.setBorderRight(XSSFCellStyle.BORDER_THIN); } else { borderStyle.setBorderRight(XSSFCellStyle.BORDER_MEDIUM); } if ((Integer.parseInt((key + ""))) != keySet.size()) { borderStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN); } else { borderStyle.setBorderBottom(XSSFCellStyle.BORDER_MEDIUM); } borderStyle.setBorderTop(XSSFCellStyle.BORDER_THIN); } } else { if (i == 7) { borderStyle.setAlignment(HorizontalAlignment.RIGHT); } XSSFFont font = workbook.createFont(); font.setFontName("Calibri"); font.setFontHeightInPoints((short) 13); font.setBold(true); borderStyle.setFont(font); } cell.setCellStyle(borderStyle); } if (key == 1) { sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6)); sheet.addMergedRegion(new CellRangeAddress(0, 0, 7, 9)); } } sheet.setColumnWidth(0, (longestCustomer + 1) * 240); sheet.setColumnWidth(1, 11 * 240); sheet.setColumnWidth(2, 5 * 240); sheet.setColumnWidth(3, 5 * 240); sheet.setColumnWidth(4, 5 * 240); sheet.setColumnWidth(5, 5 * 240); sheet.setColumnWidth(6, 5 * 240); sheet.setColumnWidth(7, 10 * 240); sheet.setColumnWidth(8, 5 * 240); for (int i = 0; i < 9; i++) { totalSize -= sheet.getColumnWidth(i); } sheet.setColumnWidth(9, totalSize); Row rowDate = sheet.createRow(keySet.size() + 1); Cell cell = rowDate.createCell(0); SimpleDateFormat sf = new SimpleDateFormat("EEE MMM yyyy HH:mm:ss"); cell.setCellValue(sf.format(Calendar.getInstance().getTime())); XSSFCellStyle cellStyle = workbook.createCellStyle(); cellStyle.setAlignment(XSSFCellStyle.ALIGN_RIGHT); cell.setCellStyle(cellStyle); sheet.addMergedRegion(new CellRangeAddress(keySet.size() + 1, keySet.size() + 1, 0, 9)); } try { workbook.write(excelOut); excelOut.close(); System.out.println("Done - Accountant"); if (!(DSC_Main.generateAllReports)) { accountLoadObj.setVisible(false); accountLoadObj.dispose(); JOptionPane.showMessageDialog(null, "AccountReports Succesfully Generated", "Success", JOptionPane.INFORMATION_MESSAGE); } else { DSC_Main.reportsDone++; if (DSC_Main.reportsDone == DSC_Main.TOTAL_REPORTS) { DSC_Main.reportsDone(); } } } catch (IOException io) { accountLoadObj.setVisible(false); accountLoadObj.dispose(); JOptionPane.showMessageDialog(null, "An error occured\nCould not create AccountReport", "Error", JOptionPane.ERROR_MESSAGE); System.err.println("Error - Could not create new AccountReport: "); io.printStackTrace(); } }
From source file:DSC.ChefReport.java
public static void processChefReport() throws IOException { boolean firstFamEntry = true; String list[] = { "Standard", "Low Carb", "Kiddies" }; int excelNumber = 0; int sheetNumber = 0; for (mealCounter = 0; mealCounter < 3; mealCounter++) { workbook = new XSSFWorkbook(); sheetNumber = 0;// w w w .j a v a 2 s . c o m for (String currRoute : allRoutes) { Map<String, Object[]> data = new TreeMap<>(); data.put(0 + "", new String[] { "Doorstep Chef - Chef Report " + DriverReport.returnWeekInt(), "", "", "Meal Type : " + list[mealCounter] + " " + " " + "Route: " + sheetNumber }); data.put(1 + "", new String[] { "", "", "", "", "", "", "" }); data.put(2 + "", new String[] { "Family Size", "Quantity", "Allergies", "Exclusions" }); int counter = 3; XSSFSheet sheet = workbook.createSheet("ChefReports Route - " + sheetNumber); int rowNum = 0; int cellNum = 0; String familysize = ""; ArrayList<Meal> mealList = new ArrayList<>(); boolean hasValue = false; for (Order order : orders) { for (Meal meal : order.getMeals()) { if (meal.getMealType().equals(list[mealCounter]) && order.getRoute().equals(currRoute)) { mealList.add(meal); hasValue = true; } } } mealList.sort(new Comparator<Meal>() { @Override public int compare(Meal o1, Meal o2) { if (o1.getQuantity() < o2.getQuantity()) { return -1; } else if (o1.getQuantity() > o2.getQuantity()) { return 1; } else { return 0; } } }); if (hasValue) { int currQuantity = 0; int bulk = 0; boolean firstIterate = true; for (Meal meal : mealList) { if (meal.getQuantity() != currQuantity) { if (!firstIterate && bulk != 0) { data.put(counter + "", new String[] { familysize + " Normal *", bulk + "", "", "" }); bulk = 0; counter++; } firstIterate = false; switch (meal.getQuantity()) { case 1: familysize = "Single"; break; case 2: familysize = "Couple"; break; case 3: familysize = "Three"; break; case 4: familysize = "Four"; break; case 5: familysize = "Five"; break; case 6: familysize = "Six"; break; default: familysize = "Extra"; } currQuantity = meal.getQuantity(); } if (meal.getAllergies().equals("-") && meal.getExclusions().equals("-")) { bulk++; } else { data.put(counter + "", new String[] { familysize + " Meal", meal.getQuantity() + "", meal.getAllergies(), meal.getExclusions() }); counter++; } } } Set<String> keySet = data.keySet(); Object[] keys = data.keySet().toArray(); Arrays.sort(keys); ArrayList<Object> keyList = new ArrayList(); int longestCustomer = 5; int totalWidth = 50000; boolean isBulk = false; for (Object key : keys) { keyList.add(data.get(key)); } for (int keyIterate = 0; keyIterate < keySet.size(); keyIterate++) { Row row = sheet.createRow(rowNum); Object[] arr = data.get(keyIterate + ""); for (int i = 0; i < arr.length; i++) { XSSFFont font = workbook.createFont(); Cell cell = row.createCell(i); cell.setCellValue((String) arr[i]); XSSFCellStyle borderStyle = workbook.createCellStyle(); if ((keyIterate + "").equals("0") || (keyIterate + "").equals("1")) { font.setFontName("Calibri"); font.setFontHeightInPoints((short) 13); font.setBold(true); borderStyle.setFont(font); borderStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex()); borderStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex()); borderStyle.setTopBorderColor(IndexedColors.BLACK.getIndex()); borderStyle.setRightBorderColor(IndexedColors.BLACK.getIndex()); borderStyle.setAlignment(HorizontalAlignment.LEFT); } else { borderStyle.setBorderBottom(BorderStyle.THIN); borderStyle.setBorderTop(BorderStyle.THIN); borderStyle.setBorderLeft(BorderStyle.THIN); borderStyle.setBorderRight(BorderStyle.THIN); if ((arr[0] + "").contains("*")) { isBulk = true; borderStyle.setBorderBottom(BorderStyle.MEDIUM); } } if ((keyIterate + "").equals("2")) { borderStyle.setBorderBottom(XSSFCellStyle.BORDER_MEDIUM); borderStyle.setBorderLeft(XSSFCellStyle.BORDER_MEDIUM); borderStyle.setBorderTop(XSSFCellStyle.BORDER_MEDIUM); borderStyle.setBorderRight(XSSFCellStyle.BORDER_MEDIUM); borderStyle.setAlignment(HorizontalAlignment.CENTER); borderStyle.setFillPattern(XSSFCellStyle.LESS_DOTS); borderStyle.setFillBackgroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); XSSFFont font2 = workbook.createFont(); font2.setColor(IndexedColors.WHITE.getIndex()); borderStyle.setFont(font2); } cell.setCellStyle(borderStyle); } rowNum++; cellNum++; } sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 2)); for (int i = 0; i < 5; i++) { switch (i) { case 1: sheet.setColumnWidth(i, 3000); break; case 2: sheet.setColumnWidth(i, 8000); break; default: sheet.setColumnWidth(i, 4000); break; } if (i == 3) { sheet.setColumnWidth(i, 8000); } } Row rowDate = sheet.createRow(keySet.size() + 1); Cell cell = rowDate.createCell(0); SimpleDateFormat sf = new SimpleDateFormat("EEE MMM yyyy HH:mm:ss"); cell.setCellValue(sf.format(Calendar.getInstance().getTime())); XSSFCellStyle cellStyle = workbook.createCellStyle(); cellStyle.setAlignment(XSSFCellStyle.ALIGN_RIGHT); cell.setCellStyle(cellStyle); sheet.addMergedRegion(new CellRangeAddress(keySet.size() + 1, keySet.size() + 1, 0, 3)); sheetNumber++; creatSheet(list[mealCounter], workbook); excelNumber++; if (excelNumber == allRoutes.size()) { if (!(DSC_Main.generateAllReports)) { chefLoadingObj.setVisible(false); chefLoadingObj.dispose(); JOptionPane.showMessageDialog(null, "Chef Reports Successfully Generated."); } } } } }