List of usage examples for org.apache.poi.ss.usermodel Workbook createSheet
Sheet createSheet(String sheetname);
From source file:Export.ExportMapaProducaoExcel__.java
public String criarDoc(String user, Date incio, Date fim) { try {/*www. j a v a 2 s .c om*/ Workbook wb = new HSSFWorkbook(); Font fTitulo = wb.createFont(); fTitulo.setBoldweight(Font.BOLDWEIGHT_BOLD); fTitulo.setFontHeightInPoints((short) 22); Font fTituloP = wb.createFont(); fTituloP.setBoldweight(Font.BOLDWEIGHT_BOLD); fTituloP.setFontHeightInPoints((short) 13); Font fTituloTabela = wb.createFont(); fTituloTabela.setBoldweight(Font.BOLDWEIGHT_BOLD); fTituloTabela.setFontHeightInPoints((short) 12.5); Font fCorpoTabela = wb.createFont(); fCorpoTabela.setBoldweight(Font.BOLDWEIGHT_NORMAL); fCorpoTabela.setFontHeightInPoints((short) 11.5); Font fRodapeTabela = wb.createFont(); fRodapeTabela.setBoldweight(Font.BOLDWEIGHT_BOLD); fRodapeTabela.setFontHeightInPoints((short) 11.5); Font fNormal = wb.createFont(); fNormal.setBoldweight(Font.BOLDWEIGHT_BOLD); fNormal.setFontHeightInPoints((short) 11); CellStyle csTitulo = wb.createCellStyle(); csTitulo.setFont(fTitulo); csTitulo.setAlignment((short) 1); csTitulo.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); csTitulo.setWrapText(true); csTitulo.setBorderBottom((short) 0); csTitulo.setBorderTop((short) 0); csTitulo.setBorderRight((short) 0); csTitulo.setBorderLeft((short) 0); csTitulo.setWrapText(true); CellStyle csTituloP = wb.createCellStyle(); csTituloP.setFont(fTituloP); csTituloP.setAlignment((short) 1); csTituloP.setVerticalAlignment((short) 1); csTituloP.setWrapText(true); csTituloP.setBorderBottom((short) 0); csTituloP.setBorderTop((short) 0); csTituloP.setBorderRight((short) 0); csTituloP.setBorderLeft((short) 0); csTituloP.setWrapText(true); CellStyle csTituloT = wb.createCellStyle(); csTituloT.setFont(fTituloP); csTituloT.setAlignment((short) 1); csTituloT.setVerticalAlignment((short) 1); csTituloT.setWrapText(true); csTituloT.setBorderBottom((short) 0); csTituloT.setBorderTop((short) 0); csTituloT.setBorderRight((short) 0); csTituloT.setBorderLeft((short) 0); csTituloT.setWrapText(true); CellStyle csTituloTabela = wb.createCellStyle(); csTituloTabela.setFont(fTituloTabela); csTituloTabela.setAlignment(CellStyle.ALIGN_CENTER); csTituloTabela.setVerticalAlignment((short) 2); csTituloTabela.setBorderBottom((short) 2); csTituloTabela.setBorderTop((short) 2); csTituloTabela.setBorderRight((short) 2); csTituloTabela.setBorderLeft((short) 2); csTituloTabela.setWrapText(true); CellStyle csCorpoTabela = wb.createCellStyle(); csCorpoTabela.setFont(fCorpoTabela); csCorpoTabela.setAlignment((short) 2); csCorpoTabela.setVerticalAlignment((short) 1); csCorpoTabela.setBorderBottom((short) 1); csCorpoTabela.setBorderTop((short) 1); csCorpoTabela.setBorderRight((short) 1); csCorpoTabela.setBorderLeft((short) 1); csCorpoTabela.setWrapText(true); CellStyle csCorpoTabelaR = wb.createCellStyle(); csCorpoTabelaR.setFont(fCorpoTabela); csCorpoTabelaR.setAlignment(CellStyle.ALIGN_RIGHT); csCorpoTabelaR.setVerticalAlignment((short) 1); csCorpoTabelaR.setBorderBottom((short) 1); csCorpoTabelaR.setBorderTop((short) 1); csCorpoTabelaR.setBorderRight((short) 1); csCorpoTabelaR.setBorderLeft((short) 1); csCorpoTabelaR.setWrapText(true); CellStyle csCorpoTabelaL = wb.createCellStyle(); csCorpoTabelaL.setFont(fCorpoTabela); csCorpoTabelaL.setAlignment(CellStyle.ALIGN_LEFT); csCorpoTabelaL.setVerticalAlignment((short) 1); csCorpoTabelaL.setBorderBottom((short) 1); csCorpoTabelaL.setBorderTop((short) 1); csCorpoTabelaL.setBorderRight((short) 1); csCorpoTabelaL.setBorderLeft((short) 1); csCorpoTabelaL.setWrapText(true); CellStyle csRodapeTabela = wb.createCellStyle(); csRodapeTabela.setFont(fRodapeTabela); csRodapeTabela.setAlignment((short) 1); csRodapeTabela.setVerticalAlignment((short) 2); csRodapeTabela.setBorderBottom((short) 2); csRodapeTabela.setBorderTop((short) 2); csRodapeTabela.setBorderRight((short) 2); csRodapeTabela.setBorderLeft((short) 2); csRodapeTabela.setWrapText(true); CellStyle csRodapeTabelaR = wb.createCellStyle(); csRodapeTabelaR.setFont(fRodapeTabela); csRodapeTabelaR.setAlignment(CellStyle.ALIGN_RIGHT); csRodapeTabelaR.setVerticalAlignment((short) 2); csRodapeTabelaR.setBorderBottom((short) 2); csRodapeTabelaR.setBorderTop((short) 2); csRodapeTabelaR.setBorderRight((short) 2); csRodapeTabelaR.setBorderLeft((short) 2); csRodapeTabelaR.setWrapText(true); CellStyle csNomal = wb.createCellStyle(); csNomal.setFont(fCorpoTabela); csNomal.setAlignment((short) 1); csNomal.setVerticalAlignment((short) 1); csNomal.setBorderBottom((short) 0); csNomal.setBorderTop((short) 0); csNomal.setBorderRight((short) 0); csNomal.setBorderLeft((short) 0); csNomal.setWrapText(true); SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy hh'.'mm'.'ss"); SimpleDateFormat sdfPt = new SimpleDateFormat("dd-MM-yyyy"); File ff = new File(getDiretorio() + "/" + user + "/Relatorio/"); ff.mkdirs(); String stringData = sdf.format(new Date()); ff = new File(ff.getAbsoluteFile() + "/" + "Export Mapa ProducaoExel " + stringData + ".xls"); String reString = "../Documentos/" + user + "/Relatorio/" + "Export Mapa ProducaoExel " + stringData + ".xls"; Sheet s = wb.createSheet("Mapa de produo de ".toUpperCase() + ((incio != null) ? sdfPt.format(incio) + " " : " dos Ultimos anos te hoje".toUpperCase()) + ((fim == null) ? "" : sdfPt.format(fim))); int linha = 0; // int pictureIdx; // try (InputStream inputStream = new FileInputStream("logo1.png")) { // byte[] bytes = IOUtils.toByteArray(inputStream); // pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG); // } // CreationHelper helper = wb.getCreationHelper(); // Drawing drawing = s.createDrawingPatriarch(); // ClientAnchor anchor = helper.createClientAnchor(); // anchor.setCol1(0); // anchor.setCol2(3); // anchor.setRow1(0); // Picture pict = drawing.createPicture(anchor, pictureIdx); // pict.resize(); Row r = s.createRow(linha); Cell c = r.createCell(2); CreateCell(c, r, s, csTitulo, linha, linha + 3, ConfigDoc.Empresa.NOME, 1, 22); linha += 4; r = s.createRow(linha); CreateCell(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.ENDERECO, 1, 22); linha++; r = s.createRow(linha); CreateCell(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.CAIXAPOSTAL, 1, 22); linha++; r = s.createRow(linha); CreateCell(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.TELEFAX + " " + ConfigDoc.Empresa.EMAIL, 1, 22); linha++; r = s.createRow(linha); CreateCell(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.SOCIEDADE, 1, 22); ResultSet rs = ud.relatorioSeguroForImpresao(incio, fim); Consumer<HashMap<String, Object>> act = (map) -> { list = new ArrayList<>(); putNewDado(map, incio, fim); }; Call.forEchaResultSet(act, rs); for (Map.Entry<String, ArrayList<Producao>> al : hasList.entrySet()) { linha += 4; r = s.createRow(linha); CreateCell(c, r, s, csTituloT, linha, linha, al.getKey(), 1, 22); linha++; linha++; r = s.createRow(linha); CreateCell(c, r, s, csTituloTabela, linha, linha, "Nr. Factura", 1, 2); CreateCell(c, r, s, csTituloTabela, linha, linha, "Nome do Segurado", 3, 7); CreateCell(c, r, s, csTituloTabela, linha, linha, "Premio", 8, 10); CreateCell(c, r, s, csTituloTabela, linha, linha, "Imposto 6%", 11, 13); CreateCell(c, r, s, csTituloTabela, linha, linha, "Imposto 5%", 14, 16); CreateCell(c, r, s, csTituloTabela, linha, linha, "FGA 2.6%", 17, 19); CreateCell(c, r, s, csTituloTabela, linha, linha, "TOTAL", 20, 22); for (Producao pro : al.getValue()) { linha++; r = s.createRow(linha); if (!pro.DATA.equals("SOMATORIO")) { CreateCell(c, r, s, csCorpoTabela, linha, linha, pro.NUMAPOLICE, 1, 2); CreateCell(c, r, s, csCorpoTabelaL, linha, linha, pro.CLIENTESEGURO, 3, 7); CreateCell(c, r, s, csCorpoTabelaR, linha, linha, pro.PREMIO + " " + pro.MOEDA, 8, 10); CreateCell(c, r, s, csCorpoTabelaR, linha, linha, pro.IMPOSTOCONSUMO + " " + pro.MOEDA, 11, 13); CreateCell(c, r, s, csCorpoTabelaR, linha, linha, pro.IMPOSTOSELO + " " + pro.MOEDA, 14, 16); CreateCell(c, r, s, csCorpoTabelaR, linha, linha, pro.FGA + " " + pro.MOEDA, 17, 19); CreateCell(c, r, s, csCorpoTabelaR, linha, linha, pro.VALORTOTAL + " " + pro.MOEDA, 20, 22); } else { CreateCell(c, r, s, csRodapeTabela, linha, linha, "Total " + al.getKey(), 1, 7); CreateCell(c, r, s, csRodapeTabelaR, linha, linha, pro.PREMIO + " " + pro.MOEDA, 8, 10); CreateCell(c, r, s, csRodapeTabelaR, linha, linha, pro.IMPOSTOCONSUMO + " " + pro.MOEDA, 11, 13); CreateCell(c, r, s, csRodapeTabelaR, linha, linha, pro.IMPOSTOSELO + " " + pro.MOEDA, 14, 16); CreateCell(c, r, s, csRodapeTabelaR, linha, linha, pro.FGA + " " + pro.MOEDA, 17, 19); CreateCell(c, r, s, csRodapeTabelaR, linha, linha, pro.VALORTOTAL + " " + pro.MOEDA, 20, 22); } } } try (FileOutputStream out = new FileOutputStream(ff)) { wb.write(out); } return reString; } catch (IOException ex) { Logger.getLogger(ExportMapaProducaoExcel__.class.getName()).log(Level.SEVERE, null, ex); return null; } }
From source file:Export.ExportViagemSemanaExcel.java
public static void criarDoc(Date dataInicio, Date dateFim, String user, String nomeFuncinario) { Workbook wb = new HSSFWorkbook(); Font fTitulo = wb.createFont(); fTitulo.setBoldweight(Font.BOLDWEIGHT_BOLD); fTitulo.setFontHeightInPoints((short) 14); Font fTituloP = wb.createFont(); fTituloP.setBoldweight(Font.BOLDWEIGHT_BOLD); fTituloP.setFontHeightInPoints((short) 12); // fTituloP.setStrikeout(true); fTituloP.setUnderline(Font.U_SINGLE); Font fTituloTabela = wb.createFont(); fTituloTabela.setBoldweight(Font.BOLDWEIGHT_BOLD); fTituloTabela.setFontHeightInPoints((short) 8); Font fCorpoTabela = wb.createFont(); fCorpoTabela.setBoldweight(Font.BOLDWEIGHT_NORMAL); fCorpoTabela.setFontHeightInPoints((short) 8.5); Font fRodapeTabela = wb.createFont(); fRodapeTabela.setBoldweight(Font.BOLDWEIGHT_BOLD); fRodapeTabela.setFontHeightInPoints((short) 8.5); Font fNormal = wb.createFont(); fNormal.setBoldweight(Font.BOLDWEIGHT_BOLD); fNormal.setFontHeightInPoints((short) 8.5); CellStyle csTitulo = wb.createCellStyle(); csTitulo.setFont(fTitulo);/*from w ww. ja v a 2 s.c o m*/ csTitulo.setAlignment((short) 1); csTitulo.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); csTitulo.setBorderBottom((short) 0); csTitulo.setBorderTop((short) 0); csTitulo.setBorderRight((short) 0); csTitulo.setBorderLeft((short) 0); csTitulo.setWrapText(true); CellStyle csTituloP = wb.createCellStyle(); csTituloP.setFont(fTituloP); csTituloP.setAlignment((short) 1); csTituloP.setVerticalAlignment((short) 1); csTituloP.setBorderBottom((short) 0); csTituloP.setBorderTop((short) 0); csTituloP.setBorderRight((short) 0); csTituloP.setBorderLeft((short) 0); csTituloP.setWrapText(true); CellStyle csTituloT = wb.createCellStyle(); csTituloT.setFont(fTituloP); csTituloT.setAlignment((short) 1); csTituloT.setVerticalAlignment((short) 1); csTituloT.setBorderBottom((short) 0); csTituloT.setBorderTop((short) 0); csTituloT.setBorderRight((short) 0); csTituloT.setBorderLeft((short) 0); csTituloT.setWrapText(true); CellStyle csTituloTabela = wb.createCellStyle(); csTituloTabela.setFont(fTituloTabela); csTituloTabela.setAlignment(CellStyle.ALIGN_CENTER); csTituloTabela.setVerticalAlignment((short) 2); csTituloTabela.setBorderBottom((short) 2); csTituloTabela.setBorderTop((short) 2); csTituloTabela.setBorderRight((short) 2); csTituloTabela.setBorderLeft((short) 2); csTituloTabela.setWrapText(true); CellStyle csTituloTabelaNBorder = wb.createCellStyle(); csTituloTabelaNBorder.setFont(fTituloTabela); csTituloTabelaNBorder.setAlignment(CellStyle.ALIGN_CENTER); csTituloTabelaNBorder.setVerticalAlignment((short) 2); csTituloTabelaNBorder.setBorderBottom((short) 2); csTituloTabelaNBorder.setBorderTop((short) 2); csTituloTabelaNBorder.setBorderRight((short) 2); csTituloTabelaNBorder.setBorderLeft((short) 2); csTituloTabelaNBorder.setWrapText(true); CellStyle csCorpoTabela = wb.createCellStyle(); csCorpoTabela.setFont(fCorpoTabela); csCorpoTabela.setAlignment((short) 2); csCorpoTabela.setVerticalAlignment((short) 1); csCorpoTabela.setBorderBottom((short) 1); csCorpoTabela.setBorderTop((short) 1); csCorpoTabela.setBorderRight((short) 1); csCorpoTabela.setBorderLeft((short) 1); csCorpoTabela.setWrapText(true); CellStyle csCorpoTabelaR = wb.createCellStyle(); csCorpoTabelaR.setFont(fCorpoTabela); csCorpoTabelaR.setAlignment(CellStyle.ALIGN_RIGHT); csCorpoTabelaR.setVerticalAlignment((short) 1); csCorpoTabelaR.setBorderBottom((short) 1); csCorpoTabelaR.setBorderTop((short) 1); csCorpoTabelaR.setBorderRight((short) 1); csCorpoTabelaR.setBorderLeft((short) 1); csCorpoTabelaR.setWrapText(true); CellStyle csCorpoTabelaL = wb.createCellStyle(); csCorpoTabelaL.setFont(fCorpoTabela); csCorpoTabelaL.setAlignment(CellStyle.ALIGN_LEFT); csCorpoTabelaL.setVerticalAlignment((short) 1); csCorpoTabelaL.setBorderBottom((short) 1); csCorpoTabelaL.setBorderTop((short) 1); csCorpoTabelaL.setBorderRight((short) 1); csCorpoTabelaL.setBorderLeft((short) 1); csCorpoTabelaL.setWrapText(true); CellStyle csRodapeTabela = wb.createCellStyle(); csRodapeTabela.setFont(fRodapeTabela); csRodapeTabela.setAlignment((short) 1); csRodapeTabela.setVerticalAlignment((short) 2); csRodapeTabela.setBorderBottom((short) 2); csRodapeTabela.setBorderTop((short) 2); csRodapeTabela.setBorderRight((short) 2); csRodapeTabela.setBorderLeft((short) 2); csRodapeTabela.setWrapText(true); CellStyle csRodapeTabelaR = wb.createCellStyle(); csRodapeTabelaR.setFont(fRodapeTabela); csRodapeTabelaR.setAlignment(CellStyle.ALIGN_RIGHT); csRodapeTabelaR.setVerticalAlignment((short) 2); csRodapeTabelaR.setBorderBottom((short) 2); csRodapeTabelaR.setBorderTop((short) 2); csRodapeTabelaR.setBorderRight((short) 2); csRodapeTabelaR.setBorderLeft((short) 2); csRodapeTabelaR.setWrapText(true); CellStyle csNomal = wb.createCellStyle(); csNomal.setFont(fCorpoTabela); csNomal.setAlignment((short) 1); csNomal.setVerticalAlignment((short) 1); csNomal.setBorderBottom((short) 0); csNomal.setBorderTop((short) 0); csNomal.setBorderRight((short) 0); csNomal.setBorderLeft((short) 0); csNomal.setWrapText(true); OutputStream outputStraem; try { SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy hh.mm.ss"); SimpleDateFormat sdfTitile = new SimpleDateFormat("dd-MM-yyyy"); File ff = new File(ConfigDoc.Fontes.getDiretorio() + "/" + user + "/Seguro Viagem/"); ff.mkdirs(); String Ddata = sdf.format(new Date()); ff = new File(ff.getAbsoluteFile() + "/" + "Export Mapa Viagem Semanal " + Ddata + ".xls"); String reString = "../Documentos/" + user + "/Seguro Viagem/" + "Export Mapa Viagem Semanal " + Ddata + ".xls"; outputStraem = new FileOutputStream(ff); int linha = 0; Sheet s = wb.createSheet("RELATORIO SEMANAL"); Row r = s.createRow(linha); Cell c = r.createCell(2); createCellM(c, r, s, csTitulo, linha, linha + 3, ConfigDoc.Empresa.NOME, 1, 22); linha += 4; r = s.createRow(linha); createCellM(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.ENDERECO, 1, 22); linha++; r = s.createRow(linha); createCellM(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.CAIXAPOSTAL, 1, 22); linha++; r = s.createRow(linha); createCellM(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.TELEFAX + " " + ConfigDoc.Empresa.EMAIL, 1, 22); linha++; r = s.createRow(linha); createCellM(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.SOCIEDADE, 1, 22); linha += 3; r = s.createRow(linha); createCellM(c, r, s, csTituloTabelaNBorder, linha, linha + 1, "RELATORIO SEMANAL NO. " + "" + "\n" + ((dataInicio != null) ? sdfTitile.format(dataInicio) + " - " : "") + ((dateFim != null) ? sdfTitile.format(dateFim) : ""), 1, 10); linha += 3; r = s.createRow(linha); c = r.createCell(2); createCell(c, r, s, csTituloTabela, linha, linha + 1, titileTable(0), 1, 4); //1 createCell(c, r, s, csTituloTabela, linha, linha + 1, titileTable(1), 2, 6); //2 createCell(c, r, s, csTituloTabela, linha, linha + 1, titileTable(2), 3, 6); //1 createCell(c, r, s, csTituloTabela, linha, linha + 1, titileTable(3), 4, 6); //1 createCell(c, r, s, csTituloTabela, linha, linha + 1, titileTable(4), 5, 6); //2 createCell(c, r, s, csTituloTabela, linha, linha + 1, titileTable(5), 6, 20); //3 createCell(c, r, s, csTituloTabela, linha, linha + 1, titileTable(6), 7, 4); //1 createCell(c, r, s, csTituloTabela, linha, linha + 1, titileTable(7), 8, 4); //1 createCell(c, r, s, csTituloTabela, linha, linha + 1, titileTable(8), 9, 8); //2 createCell(c, r, s, csTituloTabela, linha, linha + 1, titileTable(9), 10, 8); //1 createCell(c, r, s, csTituloTabela, linha, linha + 1, titileTable(10), 11, 6); //2 createCell(c, r, s, csTituloTabela, linha, linha + 1, titileTable(11), 12, 6); //2 createCell(c, r, s, csTituloTabela, linha, linha + 1, titileTable(12), 13, 6); //2 dataViagem(dataInicio, dateFim); float premiototal = 0; linha++; for (HashMap<String, Object> data : hasList) { linha++; r = s.createRow(linha); c = r.createCell(2); createCell(c, r, s, csCorpoTabelaL, linha, linha, toString(data.get(DATA)), 1, 4); createCell(c, r, s, csCorpoTabelaL, linha, linha, toString(data.get(NUMEROAPOLICE)), 2, 6); createCell(c, r, s, csCorpoTabelaL, linha, linha, ConfigDoc.toFormat(toString(data.get(INICIO)), "dd-MM-yyyy", "yyyy-MM-dd"), 3, 6); createCell(c, r, s, csCorpoTabelaL, linha, linha, ConfigDoc.toFormat(toString(data.get(FIM)), "dd-MM-yyyy", "yyyy-MM-dd"), 4, 6); premiototal += toFloat(data.get(PREMIO)); createCell(c, r, s, csCorpoTabelaR, linha, linha, ConfigDoc.toMoeda(toFloat(data.get(PREMIO)), ""), 5, 6); createCell(c, r, s, csCorpoTabelaL, linha, linha, toString(data.get(CLIENTE)), 6, 20); createCell(c, r, s, csCorpoTabelaL, linha, linha, toString(data.get(DATANASCIMENTO)), 7, 4); createCell(c, r, s, csCorpoTabelaL, linha, linha, toString(data.get(TELEFONE)), 8, 4); createCell(c, r, s, csCorpoTabelaL, linha, linha, toString(data.get(ENDERECO)), 9, 8); createCell(c, r, s, csCorpoTabelaL, linha, linha, toString(data.get(LOCALNASCIMENTO)), 10, 8); createCell(c, r, s, csCorpoTabelaL, linha, linha, toString(data.get(PAISDESTINO)), 11, 6); createCell(c, r, s, csCorpoTabelaL, linha, linha, toString(data.get(CIDADEDESTINO)), 12, 6); createCell(c, r, s, csCorpoTabelaL, linha, linha, toString(data.get(ZONADESTINO)), 13, 6); } linha++; r = s.createRow(linha); c = r.createCell(2); createCellM(c, r, s, csRodapeTabela, linha, linha, "AL AMOUNT..........................................", 1, 5); createCellM(c, r, s, csRodapeTabelaR, linha, linha, ConfigDoc.toMoeda(premiototal, ""), 6, 7); createCellM(c, r, s, csRodapeTabela, linha, linha, " ", 8, 13); try (FileOutputStream out = new FileOutputStream(ff)) { wb.write(out); } catch (IOException ex) { Logger.getLogger(GenericExcel.class.getName()).log(Level.SEVERE, null, ex); } RequestContext.getCurrentInstance().execute("openAllDocument('" + reString + "')"); } catch (FileNotFoundException ex) { Logger.getLogger(ExportViagemSemanaExcel.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Export.GenericExcel.java
/** * * @param user/*from ww w .j a v a2 s .c o m*/ * @param nomeDoc * @param titleDoc * @param rs * @param paramFilter * @return */ public static String createDoc(String user, String nomeDoc, String titleDoc, DataTableControl rs, int paramFilter) { OutputStream outputStraem = null; try { i = 0; SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MM-yyyy hh'.'mm'.'ss"); File ff = new File(ConfigDoc.Fontes.getDiretorio() + "/" + user + "/Relatorio"); ff.mkdirs(); String Ddata = sdf1.format(new Date()); ff = new File(ff.getAbsoluteFile() + "/" + nomeDoc + " " + Ddata + ".xls"); outputStraem = new FileOutputStream(ff); reString = "../Documentos/" + user + "/Relatorio/" + nomeDoc + " " + Ddata + ".xls"; getMap(rs, paramFilter); float[] colun = createPerncetage(list, paramFilter); Workbook wb = new HSSFWorkbook(); Font fTitulo = wb.createFont(); fTitulo.setBoldweight(Font.BOLDWEIGHT_BOLD); fTitulo.setFontHeightInPoints((short) 14); Font fTituloP = wb.createFont(); fTituloP.setBoldweight(Font.BOLDWEIGHT_BOLD); fTituloP.setFontHeightInPoints((short) 12); fTituloP.setUnderline(Font.U_SINGLE); Font fTituloTabela = wb.createFont(); fTituloTabela.setBoldweight(Font.BOLDWEIGHT_BOLD); fTituloTabela.setFontHeightInPoints((short) 8); Font fCorpoTabela = wb.createFont(); fCorpoTabela.setBoldweight(Font.BOLDWEIGHT_NORMAL); fCorpoTabela.setFontHeightInPoints((short) 8.5); Font fRodapeTabela = wb.createFont(); fRodapeTabela.setBoldweight(Font.BOLDWEIGHT_BOLD); fRodapeTabela.setFontHeightInPoints((short) 8.5); Font fNormal = wb.createFont(); fNormal.setBoldweight(Font.BOLDWEIGHT_BOLD); fNormal.setFontHeightInPoints((short) 8.5); CellStyle csTitulo = wb.createCellStyle(); csTitulo.setFont(fTitulo); csTitulo.setAlignment((short) 1); csTitulo.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); csTitulo.setBorderBottom((short) 0); csTitulo.setBorderTop((short) 0); csTitulo.setBorderRight((short) 0); csTitulo.setBorderLeft((short) 0); csTitulo.setWrapText(true); CellStyle csTituloP = wb.createCellStyle(); csTituloP.setFont(fTituloP); csTituloP.setAlignment((short) 1); csTituloP.setVerticalAlignment((short) 1); csTituloP.setBorderBottom((short) 0); csTituloP.setBorderTop((short) 0); csTituloP.setBorderRight((short) 0); csTituloP.setBorderLeft((short) 0); csTituloP.setWrapText(true); CellStyle csTituloT = wb.createCellStyle(); csTituloT.setFont(fTituloP); csTituloT.setAlignment((short) 1); csTituloT.setVerticalAlignment((short) 1); csTituloT.setBorderBottom((short) 0); csTituloT.setBorderTop((short) 0); csTituloT.setBorderRight((short) 0); csTituloT.setBorderLeft((short) 0); csTituloT.setWrapText(true); CellStyle csTituloTabela = wb.createCellStyle(); csTituloTabela.setFont(fTituloTabela); csTituloTabela.setAlignment(CellStyle.ALIGN_CENTER); csTituloTabela.setVerticalAlignment((short) 2); csTituloTabela.setBorderBottom((short) 2); csTituloTabela.setBorderTop((short) 2); csTituloTabela.setBorderRight((short) 2); csTituloTabela.setBorderLeft((short) 2); csTituloTabela.setWrapText(true); CellStyle csTituloTabelaNBorder = wb.createCellStyle(); csTituloTabelaNBorder.setFont(fTituloTabela); csTituloTabelaNBorder.setAlignment(CellStyle.ALIGN_CENTER); csTituloTabelaNBorder.setVerticalAlignment((short) 2); csTituloTabelaNBorder.setBorderBottom((short) 2); csTituloTabelaNBorder.setBorderTop((short) 2); csTituloTabelaNBorder.setBorderRight((short) 2); csTituloTabelaNBorder.setBorderLeft((short) 2); csTituloTabelaNBorder.setWrapText(true); CellStyle csCorpoTabela = wb.createCellStyle(); csCorpoTabela.setFont(fCorpoTabela); csCorpoTabela.setAlignment((short) 2); csCorpoTabela.setVerticalAlignment((short) 1); csCorpoTabela.setBorderBottom((short) 1); csCorpoTabela.setBorderTop((short) 1); csCorpoTabela.setBorderRight((short) 1); csCorpoTabela.setBorderLeft((short) 1); csCorpoTabela.setWrapText(true); CellStyle csCorpoTabelaR = wb.createCellStyle(); csCorpoTabelaR.setFont(fCorpoTabela); csCorpoTabelaR.setAlignment(CellStyle.ALIGN_RIGHT); csCorpoTabelaR.setVerticalAlignment((short) 1); csCorpoTabelaR.setBorderBottom((short) 1); csCorpoTabelaR.setBorderTop((short) 1); csCorpoTabelaR.setBorderRight((short) 1); csCorpoTabelaR.setBorderLeft((short) 1); csCorpoTabelaR.setWrapText(true); CellStyle csCorpoTabelaL = wb.createCellStyle(); csCorpoTabelaL.setFont(fCorpoTabela); csCorpoTabelaL.setAlignment(CellStyle.ALIGN_LEFT); csCorpoTabelaL.setVerticalAlignment((short) 1); csCorpoTabelaL.setBorderBottom((short) 1); csCorpoTabelaL.setBorderTop((short) 1); csCorpoTabelaL.setBorderRight((short) 1); csCorpoTabelaL.setBorderLeft((short) 1); csCorpoTabelaL.setWrapText(true); CellStyle csRodapeTabelaL = wb.createCellStyle(); csRodapeTabelaL.setFont(fRodapeTabela); csRodapeTabelaL.setAlignment(CellStyle.ALIGN_CENTER); csRodapeTabelaL.setVerticalAlignment((short) 2); csRodapeTabelaL.setBorderBottom((short) 2); csRodapeTabelaL.setBorderTop((short) 2); csRodapeTabelaL.setBorderRight((short) 2); csRodapeTabelaL.setBorderLeft((short) 2); csRodapeTabelaL.setWrapText(true); CellStyle csRodapeTabela = wb.createCellStyle(); csRodapeTabela.setFont(fRodapeTabela); csRodapeTabela.setAlignment(CellStyle.ALIGN_CENTER); csRodapeTabela.setVerticalAlignment((short) 2); csRodapeTabela.setBorderBottom((short) 2); csRodapeTabela.setBorderTop((short) 2); csRodapeTabela.setBorderRight((short) 2); csRodapeTabela.setBorderLeft((short) 2); csRodapeTabela.setWrapText(true); CellStyle csRodapeTabelaR = wb.createCellStyle(); csRodapeTabelaR.setFont(fRodapeTabela); csRodapeTabelaR.setAlignment(CellStyle.ALIGN_RIGHT); csRodapeTabelaR.setVerticalAlignment((short) 2); csRodapeTabelaR.setBorderBottom((short) 2); csRodapeTabelaR.setBorderTop((short) 2); csRodapeTabelaR.setBorderRight((short) 2); csRodapeTabelaR.setBorderLeft((short) 2); csRodapeTabelaR.setWrapText(true); CellStyle csNomal = wb.createCellStyle(); csNomal.setFont(fCorpoTabela); csNomal.setAlignment((short) 1); csNomal.setVerticalAlignment((short) 1); csNomal.setBorderBottom((short) 0); csNomal.setBorderTop((short) 0); csNomal.setBorderRight((short) 0); csNomal.setBorderLeft((short) 0); csNomal.setWrapText(true); Sheet s = wb.createSheet(titleDoc); linha = 0; Row r = s.createRow(linha); Cell c = r.createCell(2); createCellM(c, r, s, csTitulo, linha, linha + 3, ConfigDoc.Empresa.NOME, 1, 22); linha += 4; r = s.createRow(linha); createCellM(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.ENDERECO, 1, 22); linha++; r = s.createRow(linha); createCellM(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.CAIXAPOSTAL, 1, 22); linha++; r = s.createRow(linha); createCellM(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.TELEFAX + " " + ConfigDoc.Empresa.EMAIL, 1, 22); linha++; r = s.createRow(linha); createCellM(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.SOCIEDADE, 1, 22); linha += 3; r = s.createRow(linha); SimpleDateFormat format = new SimpleDateFormat("dd 'de' MMMM 'de' yyyy", new Locale("pt", "BR")); createCellM(c, r, s, csTituloT, linha, linha, titleDoc.toUpperCase() + ((dF != null && dI != null) ? (" de " + format.format(dI) + " " + format.format(dF)).toUpperCase() : ""), 1, 22); linha += 2; if (paramFilter < 0) { for (Object[] emap : list) { k = 0; r = s.createRow(linha); for (int j = 0; j < emap.length; j++) { if (j != paramFilterOculta) { if (i == 0) { lista_titulo_table = emap; csCorpoTabela.setFillBackgroundColor(HSSFColor.BLUE.index); createCell(c, r, s, csTituloTabela, linha, linha, toString(emap[j]), k + 1, toInt(colun[k])); k++; } else { csCorpoTabelaL.setFillBackgroundColor( ((i % 2) == 0) ? HSSFColor.WHITE.index : HSSFColor.GREY_25_PERCENT.index); createCell(c, r, s, ((alignment.containsKey(j)) ? ((alignment.get(j) == Alignment.RIGHT) ? csCorpoTabelaR : ((alignment.get(j) == Alignment.CENTER) ? csCorpoTabela : csCorpoTabelaL)) : csCorpoTabelaL), linha, linha, toString(emap[j]), k + 1, toInt(colun[k])); k++; } } } i++; linha++; } for (Map.Entry<String, ArrayList<Object[]>> entrySet : mapTotal.entrySet()) { for (Object[] emapT : entrySet.getValue()) { k = 0; r = s.createRow(linha); for (int j = 0; j < emapT.length; j++) { if (j != paramFilterOculta) { csCorpoTabelaL.setFillBackgroundColor(HSSFColor.LIGHT_BLUE.index); createCell(c, r, s, ((alignment.containsKey(j)) ? ((alignment.get(j) == Alignment.RIGHT) ? csRodapeTabelaR : ((alignment.get(j) == Alignment.CENTER) ? csRodapeTabelaR : csRodapeTabelaL)) : csRodapeTabelaL), linha, linha, ((j == 0) ? "TOTAL" : toString(emapT[j])), k + 1, toInt(colun[k])); k++; } } } } } else { int t = 0; for (Map.Entry<String, ArrayList<Object[]>> lista : map.entrySet()) { r = s.createRow(linha); csTituloTabela.setFillBackgroundColor(HSSFColor.WHITE.index); createCellM(c, r, s, csTituloTabelaNBorder, linha, linha, toString(lista.getKey()), 1, 7); linha += 2; for (Object[] emap : lista.getValue()) { k = 0; r = s.createRow(linha); for (int j = 0; j < emap.length; j++) { if (j != paramFilterOculta) { if (i == 0) { lista_titulo_table = emap; csTituloTabela.setFillBackgroundColor(HSSFColor.BLUE.index); createCell(c, r, s, csTituloTabela, linha, linha, toString(emap[j]), k + 1, toInt(colun[k])); k++; } else { csCorpoTabelaL.setFillBackgroundColor(((i % 2) == 0) ? HSSFColor.WHITE.index : HSSFColor.GREY_25_PERCENT.index); createCell(c, r, s, ((alignment.containsKey(j)) ? ((alignment.get(j) == Alignment.RIGHT) ? csCorpoTabelaR : ((alignment.get(j) == Alignment.CENTER) ? csCorpoTabela : csCorpoTabelaL)) : csCorpoTabelaL), linha, linha, toString(emap[j]), k + 1, toInt(colun[k])); k++; } } } i++; linha++; } if (mapTotal.containsKey(lista.getKey())) { for (Object[] emapT : mapTotal.get(lista.getKey())) { k = 0; r = s.createRow(linha); for (int j = 0; j < emapT.length; j++) { if (j != paramFilterOculta) { createCell(c, r, s, ((alignment.containsKey(j)) ? ((alignment.get(j) == Alignment.RIGHT) ? csRodapeTabelaR : ((alignment.get(j) == Alignment.CENTER) ? csRodapeTabela : csRodapeTabelaL)) : csRodapeTabelaL), linha, linha, ((j == 0) ? "TOTAL" : toString(emapT[j])), k + 1, toInt(colun[k])); k++; } } } } t++; i = 0; linha += 3; if (t == map.size() && paramFilter > -1) { k = 0; r = s.createRow(linha); for (int j = 0; j < lista_titulo_table.length; j++) { if (j != paramFilterOculta) { csTituloTabela.setFillBackgroundColor(HSSFColor.BLUE.index); createCell(c, r, s, csTituloTabela, linha, linha, toString(lista_titulo_table[j]), k + 1, toInt(colun[k])); k++; } } linha++; Double[] total_total = new Double[lista_titulo_table.length]; for (Map.Entry<String, ArrayList<Object[]>> lista_for_total : map.entrySet()) { String key = lista_for_total.getKey(); for (Object[] emapT : mapTotal.get(key)) { k = 0; r = s.createRow(linha); for (int j = 0; j < emapT.length; j++) { if (j != paramFilterOculta) { if (Moeda.unFormat(toString(emapT[j]).replaceAll(" ", "") .replaceAll(",", ".").replaceAll("STD", "")) != -1) { Double v = ((total_total[j] == null) ? 0.0 : total_total[j]); total_total[j] = Moeda.unFormat(toString(emapT[j]).replaceAll(" ", "") .replaceAll(",", ".").replaceAll("STD", "")) + v; } createCell(c, r, s, ((alignment.containsKey(j)) ? ((alignment.get(j) == Alignment.RIGHT) ? csRodapeTabelaR : ((alignment.get(j) == Alignment.CENTER) ? csRodapeTabela : csRodapeTabelaL)) : csRodapeTabelaL), linha, linha, ((j == 0) ? "TOTAL " + key.toUpperCase() : toString(emapT[j])), k + 1, toInt(colun[k])); k++; } } } linha++; } k = 0; r = s.createRow(linha); for (int j = 0; j < total_total.length; j++) { if (j != paramFilterOculta) { csTituloTabela.setFillBackgroundColor(HSSFColor.BLUE.index); createCell(c, r, s, ((alignment.containsKey(j)) ? ((alignment.get(j) == Alignment.RIGHT) ? csRodapeTabelaR : ((alignment.get(j) == Alignment.CENTER) ? csRodapeTabela : csRodapeTabelaL)) : csRodapeTabelaL), linha, linha, (total_total[j] != null) ? Moeda.format_are(total_total[j]) : " ", k + 1, toInt(colun[k])); k++; } } } } } try (FileOutputStream out = new FileOutputStream(ff)) { wb.write(out); } catch (IOException ex) { Logger.getLogger(GenericExcel.class.getName()).log(Level.SEVERE, null, ex); } RequestContext.getCurrentInstance().execute("openAllDocument('" + reString + "')"); no = false; nomeNo = ""; dI = null; dF = null; paramFilterOculta = -1; removeItem = new int[] {}; renameItem = new HashMap<>(); alignment = new HashMap<>(); valoresTotal = new String[] {}; arrValoresTotal = new int[] {}; return reString; } catch (FileNotFoundException ex) { Logger.getLogger(GenericExcel.class.getName()).log(Level.SEVERE, null, ex); return reString; } }
From source file:Export.ListaVeiculo.java
public static void criarDocExcel(List<Veiculo> ls, String user) { try {// w w w.ja v a2 s . com SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MM-yyyy hh'.'mm'.'ss"); File ff = new File(ConfigDoc.Fontes.getDiretorio() + "/" + user + "/Relatorio"); ff.mkdirs(); String Ddata = sdf1.format(new Date()); ff = new File(ff.getAbsoluteFile() + "/" + "Lista de Veiculos" + " " + Ddata + ".xls"); FileOutputStream outputStraem = new FileOutputStream(ff); String reString = "../Documentos/" + user + "/Relatorio/" + "Lista de Veiculos" + " " + Ddata + ".xls"; Workbook wb = new HSSFWorkbook(); org.apache.poi.ss.usermodel.Font fTitulo = wb.createFont(); fTitulo.setBoldweight(org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_BOLD); fTitulo.setFontHeightInPoints((short) 22); org.apache.poi.ss.usermodel.Font fTituloP = wb.createFont(); fTituloP.setBoldweight(org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_BOLD); fTituloP.setFontHeightInPoints((short) 15); // fTituloP.setStrikeout(true); fTituloP.setUnderline(org.apache.poi.ss.usermodel.Font.U_SINGLE); org.apache.poi.ss.usermodel.Font fTituloTabela = wb.createFont(); fTituloTabela.setBoldweight(org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_BOLD); fTituloTabela.setFontHeightInPoints((short) 11); org.apache.poi.ss.usermodel.Font fCorpoTabela = wb.createFont(); fCorpoTabela.setBoldweight(org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_NORMAL); fCorpoTabela.setFontHeightInPoints((short) 11.5); org.apache.poi.ss.usermodel.Font fRodapeTabela = wb.createFont(); fRodapeTabela.setBoldweight(org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_BOLD); fRodapeTabela.setFontHeightInPoints((short) 11.5); org.apache.poi.ss.usermodel.Font fNormal = wb.createFont(); fNormal.setBoldweight(org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_BOLD); fNormal.setFontHeightInPoints((short) 11); CellStyle csTitulo = wb.createCellStyle(); csTitulo.setFont(fTitulo); csTitulo.setAlignment((short) 1); csTitulo.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); // csTitulo.setWrapText(true); csTitulo.setBorderBottom((short) 0); csTitulo.setBorderTop((short) 0); csTitulo.setBorderRight((short) 0); csTitulo.setBorderLeft((short) 0); // csTitulo.setWrapText(true); CellStyle csTituloP = wb.createCellStyle(); csTituloP.setFont(fTituloP); csTituloP.setAlignment((short) 1); csTituloP.setVerticalAlignment((short) 1); // csTituloP.setWrapText(true); csTituloP.setBorderBottom((short) 0); csTituloP.setBorderTop((short) 0); csTituloP.setBorderRight((short) 0); csTituloP.setBorderLeft((short) 0); // csTituloP.setWrapText(true); CellStyle csTituloT = wb.createCellStyle(); csTituloT.setFont(fTituloP); csTituloT.setAlignment((short) 1); csTituloT.setVerticalAlignment((short) 1); // csTituloT.setWrapText(true); csTituloT.setBorderBottom((short) 0); csTituloT.setBorderTop((short) 0); csTituloT.setBorderRight((short) 0); csTituloT.setBorderLeft((short) 0); // csTituloT.setWrapText(true); CellStyle csTituloTabela = wb.createCellStyle(); csTituloTabela.setFont(fTituloTabela); csTituloTabela.setAlignment(CellStyle.ALIGN_CENTER); csTituloTabela.setVerticalAlignment((short) 2); csTituloTabela.setBorderBottom((short) 2); csTituloTabela.setBorderTop((short) 2); csTituloTabela.setBorderRight((short) 2); csTituloTabela.setBorderLeft((short) 2); // csTituloTabela.setWrapText(true); CellStyle csCorpoTabela = wb.createCellStyle(); csCorpoTabela.setFont(fCorpoTabela); csCorpoTabela.setAlignment((short) 2); csCorpoTabela.setVerticalAlignment((short) 1); csCorpoTabela.setBorderBottom((short) 1); csCorpoTabela.setBorderTop((short) 1); csCorpoTabela.setBorderRight((short) 1); csCorpoTabela.setBorderLeft((short) 1); // csCorpoTabela.setWrapText(true); CellStyle csCorpoTabelaR = wb.createCellStyle(); csCorpoTabelaR.setFont(fCorpoTabela); csCorpoTabelaR.setAlignment(CellStyle.ALIGN_RIGHT); csCorpoTabelaR.setVerticalAlignment((short) 1); csCorpoTabelaR.setBorderBottom((short) 1); csCorpoTabelaR.setBorderTop((short) 1); csCorpoTabelaR.setBorderRight((short) 1); csCorpoTabelaR.setBorderLeft((short) 1); // csCorpoTabelaR.setWrapText(true); CellStyle csCorpoTabelaL = wb.createCellStyle(); csCorpoTabelaL.setFont(fCorpoTabela); csCorpoTabelaL.setAlignment(CellStyle.ALIGN_LEFT); csCorpoTabelaL.setVerticalAlignment((short) 1); csCorpoTabelaL.setBorderBottom((short) 1); csCorpoTabelaL.setBorderTop((short) 1); csCorpoTabelaL.setBorderRight((short) 1); csCorpoTabelaL.setBorderLeft((short) 1); // csCorpoTabelaL.setWrapText(true); CellStyle csRodapeTabela = wb.createCellStyle(); csRodapeTabela.setFont(fRodapeTabela); csRodapeTabela.setAlignment((short) 1); csRodapeTabela.setVerticalAlignment((short) 2); csRodapeTabela.setBorderBottom((short) 2); csRodapeTabela.setBorderTop((short) 2); csRodapeTabela.setBorderRight((short) 2); csRodapeTabela.setBorderLeft((short) 2); // csRodapeTabela.setWrapText(true); CellStyle csRodapeTabelaR = wb.createCellStyle(); csRodapeTabelaR.setFont(fRodapeTabela); csRodapeTabelaR.setAlignment(CellStyle.ALIGN_RIGHT); csRodapeTabelaR.setVerticalAlignment((short) 2); csRodapeTabelaR.setBorderBottom((short) 2); csRodapeTabelaR.setBorderTop((short) 2); csRodapeTabelaR.setBorderRight((short) 2); csRodapeTabelaR.setBorderLeft((short) 2); // csRodapeTabelaR.setWrapText(true); CellStyle csNomal = wb.createCellStyle(); csNomal.setFont(fCorpoTabela); csNomal.setAlignment((short) 1); csNomal.setVerticalAlignment((short) 1); csNomal.setBorderBottom((short) 0); csNomal.setBorderTop((short) 0); csNomal.setBorderRight((short) 0); csNomal.setBorderLeft((short) 0); // csNomal.setWrapText(true); Sheet s = wb.createSheet("Lista de Veiculos"); short linha = 0; Row r = s.createRow(linha); Cell c = r.createCell(2); CreateCellM(c, r, s, csTitulo, linha, linha + 3, ConfigDoc.Empresa.NOME, 1, 22); linha += 4; r = s.createRow(linha); CreateCellM(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.ENDERECO, 1, 22); linha++; r = s.createRow(linha); CreateCellM(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.CAIXAPOSTAL, 1, 22); linha++; r = s.createRow(linha); CreateCellM(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.TELEFAX + " " + ConfigDoc.Empresa.EMAIL, 1, 22); linha++; r = s.createRow(linha); CreateCellM(c, r, s, csTituloP, linha, linha, ConfigDoc.Empresa.SOCIEDADE, 1, 22); linha += 3; r = s.createRow(linha); CreateCellM(c, r, s, csTituloT, linha, linha, "Lista de Veiculos".toUpperCase(), 1, 22); linha += 2; csCorpoTabela.setFillBackgroundColor(HSSFColor.BLUE.index); r = s.createRow(linha); CreateCell(c, r, s, csTituloTabela, linha, linha, getList(0), 1, 8); CreateCell(c, r, s, csTituloTabela, linha, linha, getList(1), 2, 18); CreateCell(c, r, s, csTituloTabela, linha, linha, getList(2), 3, 18); CreateCell(c, r, s, csTituloTabela, linha, linha, getList(3), 4, 18); CreateCell(c, r, s, csTituloTabela, linha, linha, getList(4), 5, 18); CreateCell(c, r, s, csTituloTabela, linha, linha, getList(5), 6, 10); CreateCell(c, r, s, csTituloTabela, linha, linha, getList(6), 7, 10); CreateCell(c, r, s, csTituloTabela, linha, linha, getList(7), 8, 8); linha++; for (int i = 0; i < ls.size(); i++) { r = s.createRow(linha); csCorpoTabelaL.setFillBackgroundColor( ((i % 2) == 0) ? HSSFColor.WHITE.index : HSSFColor.GREY_25_PERCENT.index); CreateCell(c, r, s, csCorpoTabelaL, linha, linha, ls.get(i).getNumeroMatricula(), 1, 8); CreateCell(c, r, s, csCorpoTabelaL, linha, linha, ls.get(i).getMarca(), 2, 18); CreateCell(c, r, s, csCorpoTabelaL, linha, linha, ls.get(i).getModelo(), 3, 18); CreateCell(c, r, s, csCorpoTabelaL, linha, linha, ls.get(i).getNumMotor(), 4, 18); CreateCell(c, r, s, csCorpoTabelaL, linha, linha, ls.get(i).getChassi(), 5, 18); CreateCell(c, r, s, csCorpoTabelaL, linha, linha, (ls.get(i).getAnoFabrico() == null || ls.get(i).getAnoFabrico().equals("")) ? "" : Integer.valueOf(ls.get(i).getAnoFabrico()), 6, 10); CreateCell(c, r, s, csCorpoTabelaL, linha, linha, (ls.get(i).getAnoCompra() == null || ls.get(i).getAnoCompra().equals("")) ? "" : Integer.valueOf(ls.get(i).getAnoCompra()), 7, 10); CreateCell(c, r, s, csCorpoTabelaL, linha, linha, Integer.valueOf(ls.get(i).getCapacidade()), 8, 8); linha++; } try (FileOutputStream out = new FileOutputStream(ff)) { wb.write(out); } catch (IOException ex) { Logger.getLogger(GenericExcel.class.getName()).log(Level.SEVERE, null, ex); } RequestContext.getCurrentInstance().execute("openAllDocument('" + reString + "')"); } catch (IOException ex) { Logger.getLogger(GenericExcel.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:facebook.insights.Inicio.java
/** * @param args the command line arguments *//* ww w .ja va 2 s . co m*/ public static void main(String[] args) { // El Token solo dura 2 meses Metricas issuac = new Metricas( "CAAImAGMzn20BAF8yhGFZBNXP8LEnZCElzzSoX0Ll6uY1APzZBnAT9LVZCQ0dP1AKPxL8C1qybyyz7xfGCOLo3ew3W3IpJkZC8XNKvEsywyCCZBOaicIA1tQZCFWknQ1MdREu2BZCAoK3M0Y6yvm0whZCKgWrNHF4AuA8eSm8saoxIiUtqNFf3cq4F", "120472297979101"); Inicio obj = new Inicio(); try { // Se crea el libro Workbook libro = new XSSFWorkbook(); // Se crea una hoja dentro del libro Sheet hoja = libro.createSheet("Metricas 2014 by Flock"); // Se crea una fila dentro de la hoja Row fila = hoja.createRow(0); // Se crea una celda dentro de la fila Cell celda = fila.createCell(1); // Se crea el contenido de la celda y se mete en ella. celda.setCellValue("Insights X"); List<Row> filas = new ArrayList<>(); int recorrete = 1; for (int e = 2; e < 255; e++) { Row filad = hoja.createRow(e); filas.add(filad); } /************************************/ // Metrica // JSONObject ob = issuac.page_fan_removes(); JSONArray x = ob.getJSONArray("data"); JSONArray y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_fan_removes", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_fan_removes_unique(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_fan_removes_unique", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_fan_adds_by_paid_non_paid_unique(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_fan_adds_by_paid_non_paid_unique", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_fan_adds(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_fan_adds", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_fan_adds_unique(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_fan_adds_unique", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_views_login_unique_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_views_login_unique_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_views_login_unique_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_views_login_unique_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_views_login_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_views_login_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_views_login_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_views_login_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_views_logout_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_views_logout_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_views(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_views", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_tab_views_login_top_unique_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_tab_views_login_top_unique_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_tab_views_login_top_unique_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_tab_views_login_top_unique_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_tab_views_login_top_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_tab_views_login_top_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_tab_views_login_top_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_tab_views_login_top_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_tab_views_logout_top_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_tab_views_logout_top_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_views_external_referrals_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_views_external_referrals_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_story_adds_unique_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_story_adds_unique_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_story_adds_unique_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_story_adds_unique_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_story_adds_unique_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_story_adds_unique_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_story_adds_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_story_adds_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_story_adds_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_story_adds_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_story_adds_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_story_adds_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_story_adds_by_story_type_unique_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_story_adds_by_story_type_unique_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_story_adds_by_story_type_unique_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_story_adds_by_story_type_unique_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_story_adds_by_story_type_unique_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_story_adds_by_story_type_unique_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_story_adds_by_story_type_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_story_adds_by_story_type_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_story_adds_by_story_type_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_story_adds_by_story_type_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_story_adds_by_story_type_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_story_adds_by_story_type_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_by_age_gender_unique_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_by_age_gender_unique_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_by_age_gender_unique_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_by_age_gender_unique_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_by_age_gender_unique_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_by_age_gender_unique_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_by_country_unique_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_by_country_unique_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_by_country_unique_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_by_country_unique_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_by_country_unique_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_by_country_unique_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_by_locale_unique_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_by_locale_unique_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_by_locale_unique_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_by_locale_unique_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_by_locale_unique_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_by_locale_unique_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_by_city_unique_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_by_city_unique_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_by_city_unique_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_by_city_unique_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_by_city_unique_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_by_city_unique_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_story_adds_by_age_gender_unique_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_story_adds_by_age_gender_unique_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_story_adds_by_age_gender_unique_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_story_adds_by_age_gender_unique_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_story_adds_by_country_unique_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_story_adds_by_country_unique_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_story_adds_by_country_unique_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_story_adds_by_country_unique_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_story_adds_by_country_unique_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_story_adds_by_country_unique_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_story_adds_by_city_unique_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_story_adds_by_city_unique_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_story_adds_by_city_unique_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_story_adds_by_city_unique_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_story_adds_by_city_unique_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_story_adds_by_city_unique_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_story_adds_by_locale_unique_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_story_adds_by_locale_unique_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_story_adds_by_locale_unique_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_story_adds_by_locale_unique_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_story_adds_by_locale_unique_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_story_adds_by_locale_unique_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_unique_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_unique_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_unique_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_unique_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_unique_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_unique_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_paid_unique_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_paid_unique_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_paid_unique_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_paid_unique_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_paid_unique_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_paid_unique_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_paid_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_paid_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_paid_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_paid_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_paid_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_paid_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_organic_unique_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_organic_unique_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_organic_unique_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_organic_unique_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_organic_unique_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_organic_unique_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_organic_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_organic_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_organic_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_organic_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_organic_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_organic_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_viral_unique_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_viral_unique_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_viral_unique_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_viral_unique_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_viral_unique_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_viral_unique_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_viral_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_viral_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_viral_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_viral_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_viral_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_viral_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_by_story_type_unique_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_by_story_type_unique_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_by_story_type_unique_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_by_story_type_unique_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_by_story_type_unique_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_by_story_type_unique_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_by_story_type_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_by_story_type_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_by_story_type_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_by_story_type_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_by_story_type_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_by_story_type_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_by_paid_non_paid_unique_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_by_paid_non_paid_unique_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_by_paid_non_paid_unique_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_by_paid_non_paid_unique_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_by_paid_non_paid_unique_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_by_paid_non_paid_unique_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_by_paid_non_paid_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_by_paid_non_paid_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_by_paid_non_paid_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_by_paid_non_paid_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_impressions_by_paid_non_paid_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_impressions_by_paid_non_paid_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_places_checkin_total_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_places_checkin_total_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_places_checkin_total_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_places_checkin_total_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_places_checkin_total_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_places_checkin_total_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_places_checkin_total_unique_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_places_checkin_total_unique_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_places_checkin_total_unique_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_places_checkin_total_unique_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_places_checkin_total_unique_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_places_checkin_total_unique_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_places_checkin_mobile_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_places_checkin_mobile_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_places_checkin_mobile_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_places_checkin_mobile_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_places_checkin_mobile_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_places_checkin_mobile_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_places_checkin_mobile_unique_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_places_checkin_mobile_unique_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_places_checkin_mobile_unique_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_places_checkin_mobile_unique_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_places_checkin_mobile_unique_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_places_checkin_mobile_unique_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_posts_impressions_unique_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_posts_impressions_unique_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_posts_impressions_unique_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_posts_impressions_unique_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_posts_impressions_unique_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_posts_impressions_unique_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_posts_impressions_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_posts_impressions_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_posts_impressions_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_posts_impressions_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_posts_impressions_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_posts_impressions_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_posts_impressions_paid_unique_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_posts_impressions_paid_unique_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_posts_impressions_paid_unique_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_posts_impressions_paid_unique_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_posts_impressions_paid_unique_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_posts_impressions_paid_unique_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_posts_impressions_paid_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_posts_impressions_paid_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_posts_impressions_paid_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_posts_impressions_paid_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_posts_impressions_paid_days_28(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_posts_impressions_paid_days_28", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_posts_impressions_organic_unique_day(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_posts_impressions_organic_unique_day", hoja, y, filas); recorrete += 3; /*****************************************************************/ // Metrica // ob = issuac.page_posts_impressions_organic_unique_week(); x = ob.getJSONArray("data"); y = (JSONArray) x.getJSONObject(0).get("values"); obj.recorre(recorrete, "page_posts_impressions_organic_unique_week", hoja, y, filas); recorrete += 3; /*****************************************************************/ FileOutputStream elFichero = new FileOutputStream("Metricas.xlsx"); libro.write(elFichero); elFichero.close(); } catch (Exception e) { System.err.println("Fallo" + e); } }
From source file:facebook.insights.MetricaX.java
public static void main(String[] args) { MetricaX obj = new MetricaX(); Facebook facebook = null;/*from ww w . ja v a 2s. com*/ List<ResponseList<Post>> X = null; try { // Se crea el libro Workbook libro = new XSSFWorkbook(); // Se crea una hoja dentro del libro Sheet hoja = libro.createSheet("Metricas 2014 by Flock"); // Se crea una fila dentro de la hoja Row fila = hoja.createRow(0); // Se crea una celda dentro de la fila Cell celda = fila.createCell(1); // Se crea el contenido de la celda y se mete en ella. celda.setCellValue("Insights Infinitum por Post"); List<Row> filas = new ArrayList<>(); for (int e = 2; e < 1048576; e++) { Row filad = hoja.createRow(e); filas.add(filad); } facebook = new FacebookFactory().getInstance(); facebook.setOAuthAppId("603320016402931", "202694064e7a4e77f0c0042b1a16ebd4"); System.out.println(facebook.getOAuthAppAccessToken().getToken()); ResponseList<Post> feedX = facebook.getFeed("216786388331757", new Reading().limit(1000)); X = new ArrayList<ResponseList<Post>>(); int ui = 0; do { X.add(feedX); Paging<Post> pag1 = feedX.getPaging(); feedX = facebook.fetchNext(pag1); System.out.println("" + ui); ui++; } while (feedX.getPaging() != null && ui < 23); int fia = 2; for (int j = 0; j < X.size(); j++) { int recorrete = 4; ResponseList<Post> feed = X.get(j); System.out.println(feed.size()); for (int i = 0; i < feed.size(); i++) { System.out.println("Feed: " + i); String posttext = feed.get(i).getMessage() + ""; String fecha = feed.get(i).getCreatedTime() + ""; obj.bloque(obj, feed.get(i).getId() + "", recorrete, hoja, filas, fia, posttext, fecha); fia += 6; } } FileOutputStream elFichero = new FileOutputStream("MetricasAaron2.xlsx"); libro.write(elFichero); elFichero.close(); } catch (Exception e) { System.err.println("En Main: " + e); } }
From source file:featurescomparison.workingwithcellsrowscolumns.splitpanes.java.ApacheSplitPanes.java
License:Apache License
public static void main(String[] args) throws Exception { String dataPath = "src/featurescomparison/workingwithcellsrowscolumns/splitpanes/data/"; Workbook wb = new XSSFWorkbook(); Sheet sheet = wb.createSheet("new sheet"); // Create a split with the lower left side being the active quadrant sheet.createSplitPane(2000, 2000, 0, 0, Sheet.PANE_LOWER_LEFT); FileOutputStream fileOut = new FileOutputStream(dataPath + "ApacheSplitFreezePanes.xlsx"); wb.write(fileOut);//from www . j av a 2s . c o m fileOut.close(); System.out.println("Done."); }
From source file:featurescomparison.workingwithworkbook.fittoonepage.java.ApacheFitSheetToOnePage.java
License:Apache License
public static void main(String[] args) throws Exception { String dataPath = "src/featurescomparison/workingwithworkbook/fittoonepage/data/"; Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook(); Sheet sheet = wb.createSheet("format sheet"); PrintSetup ps = sheet.getPrintSetup(); sheet.setAutobreaks(true);/*ww w .ja v a 2 s.com*/ ps.setFitHeight((short) 1); ps.setFitWidth((short) 1); // Create various cells and rows for spreadsheet. FileOutputStream fileOut = new FileOutputStream(dataPath + "ApacheFitSheetToOnePage.xlsx"); wb.write(fileOut); fileOut.close(); System.out.println("Done."); }
From source file:featurescomparison.workingwithworksheets.fittoonepage.java.ApacheFitSheetToOnePage.java
License:Apache License
public static void main(String[] args) throws Exception { String dataPath = "src/featurescomparison/workingwithworksheets/fittoonepage/data/"; Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook(); Sheet sheet = wb.createSheet("format sheet"); PrintSetup ps = sheet.getPrintSetup(); sheet.setAutobreaks(true);/*w w w. j a va2 s . c o m*/ ps.setFitHeight((short) 1); ps.setFitWidth((short) 1); // Create various cells and rows for spreadsheet. FileOutputStream fileOut = new FileOutputStream(dataPath + "ApacheFitSheetToOnePage.xlsx"); wb.write(fileOut); fileOut.close(); System.out.println("Done."); }
From source file:fi.semantum.strategia.Main.java
License:Open Source License
@Override protected void init(VaadinRequest request) { getPage().addUriFragmentChangedListener(new UriFragmentChangedListener() { public void uriFragmentChanged(UriFragmentChangedEvent source) { applyFragment(source.getUriFragment(), true); }//from w w w .ja v a 2 s. c o m }); String pathInfo = request.getPathInfo(); if (pathInfo.startsWith("/")) pathInfo = pathInfo.substring(1); if (pathInfo.endsWith("/")) pathInfo = pathInfo.substring(0, pathInfo.length() - 1); String databaseId = validatePathInfo(pathInfo); setWindowWidth(Page.getCurrent().getBrowserWindowWidth(), Page.getCurrent().getBrowserWindowHeight()); // Find the application directory String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); // Image as a file resource redResource = new FileResource(new File(basepath + "/WEB-INF/images/bullet_red.png")); greenResource = new FileResource(new File(basepath + "/WEB-INF/images/bullet_green.png")); blackResource = new FileResource(new File(basepath + "/WEB-INF/images/bullet_black.png")); mapMagnify = new FileResource(new File(basepath + "/WEB-INF/images/map_magnify.png")); abs = new AbsoluteLayout(); final VerticalLayout vs = new VerticalLayout(); vs.setSizeFull(); abs.addComponent(vs); setContent(abs); // This will set the login cookie Wiki.login(this); // Make sure that the printing directory exists new File(Main.baseDirectory(), "printing").mkdirs(); database = Database.load(this, databaseId); database.getOrCreateTag("Tavoite"); database.getOrCreateTag("Painopiste"); for (Strategiakartta map : Strategiakartta.enumerate(database)) { Strategiakartta parent = map.getPossibleParent(database); if (parent == null) uiState.setCurrentMap(parent); } if (uiState.getCurrentMap() == null) uiState.setCurrentMap(database.getRoot()); uiState.currentPosition = uiState.getCurrentMap(); uiState.currentItem = uiState.getCurrentMap(); setPollInterval(10000); addPollListener(new PollListener() { @Override public void poll(PollEvent event) { if (database.checkChanges()) { String curr = uiState.getCurrentMap().uuid; database = Database.load(Main.this, database.getDatabaseId()); uiState.setCurrentMap((Strategiakartta) database.find(curr)); Updates.updateJS(Main.this, false); } } }); js.addListener(new MapListener(this, false)); js2.addListener(new MapListener(this, true)); browser_.addListener(new BrowserListener() { @Override public void select(double x, double y, String uuid) { Base b = database.find(uuid); Actions.selectAction(Main.this, x, y, null, b); } @Override public void save(String name, Map<String, BrowserNodeState> states) { UIState state = getUIState().duplicate(name); state.browserStates = states; account.uiStates.add(state); Updates.update(Main.this, true); } }); Page.getCurrent().addBrowserWindowResizeListener(new BrowserWindowResizeListener() { @Override public void browserWindowResized(BrowserWindowResizeEvent event) { setWindowWidth(event.getWidth(), event.getHeight()); Updates.updateJS(Main.this, false); } }); modeLabel = new Label("Katselutila"); modeLabel.setWidth("95px"); modeLabel.addStyleName("viewMode"); mode = new Button(); mode.setDescription("Siirry tiedon sytttilaan"); mode.setIcon(FontAwesome.EYE); mode.addStyleName(ValoTheme.BUTTON_TINY); mode.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { if ("Siirry tiedon sytttilaan".equals(mode.getDescription())) { mode.setDescription("Siirry katselutilaan"); mode.setIcon(FontAwesome.PENCIL); modeLabel.setValue("Sytttila"); modeLabel.removeStyleName("viewMode"); modeLabel.addStyleName("editMode"); UIState s = uiState.duplicate(Main.this); s.input = true; setFragment(s, true); } else { mode.setDescription("Siirry tiedon sytttilaan"); mode.setIcon(FontAwesome.EYE); modeLabel.setValue("Katselutila"); modeLabel.removeStyleName("editMode"); modeLabel.addStyleName("viewMode"); UIState s = uiState.duplicate(Main.this); s.input = false; setFragment(s, true); } } }); meterMode = new Button(); meterMode.setDescription("Vaihda toteumamittareihin"); meterMode.setCaption("Ennuste"); meterMode.addStyleName(ValoTheme.BUTTON_TINY); meterMode.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { if ("Vaihda toteumamittareihin".equals(meterMode.getDescription())) { meterMode.setDescription("Vaihda ennustemittareihin"); meterMode.setCaption("Toteuma"); UIState s = uiState.duplicate(Main.this); s.setActualMeters(); setFragment(s, true); } else { meterMode.setDescription("Vaihda toteumamittareihin"); meterMode.setCaption("Ennuste"); UIState s = uiState.duplicate(Main.this); s.setForecastMeters(); setFragment(s, true); } } }); pdf = new PDFButton(); pdf.setDescription("Tallenna kartta PDF-muodossa"); pdf.setIcon(FontAwesome.PRINT); pdf.addStyleName(ValoTheme.BUTTON_TINY); pdf.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { Utils.print(Main.this); } }); propertyExcelButton = new Button(); propertyExcelButton.setDescription("Tallenna tiedot Excel-tiedostona"); propertyExcelButton.setIcon(FontAwesome.PRINT); propertyExcelButton.addStyleName(ValoTheme.BUTTON_TINY); OnDemandFileDownloader dl = new OnDemandFileDownloader(new OnDemandStreamSource() { private static final long serialVersionUID = 981769438054780731L; File f; Date date = new Date(); @Override public InputStream getStream() { String uuid = UUID.randomUUID().toString(); File printing = new File(Main.baseDirectory(), "printing"); f = new File(printing, uuid + ".xlsx"); Workbook w = new XSSFWorkbook(); Sheet sheet = w.createSheet("Sheet1"); int row = 1; for (List<String> cells : propertyCells) { Row r = sheet.createRow(row++); for (int i = 0; i < cells.size(); i++) { String value = cells.get(i); r.createCell(i).setCellValue(value); } } try { FileOutputStream s = new FileOutputStream(f); w.write(s); s.close(); } catch (Exception e) { e.printStackTrace(); } try { return new FileInputStream(f); } catch (FileNotFoundException e) { e.printStackTrace(); } throw new IllegalStateException(); } @Override public void onRequest() { } @Override public long getFileSize() { return f.length(); } @Override public String getFileName() { return "Strategiakartta_" + Utils.dateString(date) + ".xlsx"; } }); dl.getResource().setCacheTime(0); dl.extend(propertyExcelButton); states = new ComboBox(); states.setWidth("250px"); states.addStyleName(ValoTheme.COMBOBOX_TINY); states.setInvalidAllowed(false); states.setNullSelectionAllowed(false); states.addValueChangeListener(statesListener); saveState = new Button(); saveState.setEnabled(false); saveState.setDescription("Tallenna nykyinen nkym"); saveState.setIcon(FontAwesome.BOOKMARK); saveState.addStyleName(ValoTheme.BUTTON_TINY); saveState.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { Utils.saveCurrentState(Main.this); } }); class SearchTextField extends TextField { public boolean hasFocus = false; } final SearchTextField search = new SearchTextField(); search.setWidth("100%"); search.addStyleName(ValoTheme.TEXTFIELD_TINY); search.addStyleName(ValoTheme.TEXTFIELD_BORDERLESS); search.setInputPrompt("hae vapaasanahaulla valitun asian alta"); search.setId("searchTextField"); search.addShortcutListener(new ShortcutListener("Shortcut Name", ShortcutAction.KeyCode.ENTER, null) { @Override public void handleAction(Object sender, Object target) { if (!search.hasFocus) return; String text = search.getValue().toLowerCase(); try { Map<String, String> content = new HashMap<String, String>(); List<String> hits = Lucene.search(database.getDatabaseId(), text + "*"); for (String uuid : hits) { Base b = database.find(uuid); if (b != null) { String report = ""; Map<String, String> map = b.searchMap(database); for (Map.Entry<String, String> e : map.entrySet()) { if (e.getValue().contains(text)) { if (!report.isEmpty()) report += ", "; report += e.getKey(); } } if (!report.isEmpty()) content.put(uuid, report); } } uiState.setCurrentFilter(new SearchFilter(Main.this, content)); Updates.updateJS(Main.this, false); switchToBrowser(); } catch (IOException e) { e.printStackTrace(); } } }); search.addFocusListener(new FocusListener() { @Override public void focus(FocusEvent event) { search.hasFocus = true; } }); search.addBlurListener(new BlurListener() { @Override public void blur(BlurEvent event) { search.hasFocus = false; } }); hallinnoi = new Button("Hallinnoi"); hallinnoi.setWidthUndefined(); hallinnoi.setVisible(false); hallinnoi.addStyleName(ValoTheme.BUTTON_TINY); hallinnoi.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { if (account != null) { if (account.isAdmin()) { Utils.manage(Main.this); } } } }); tili = new Button("Kyttjtili"); tili.setWidthUndefined(); tili.setVisible(false); tili.addStyleName(ValoTheme.BUTTON_TINY); tili.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { if (account != null) { Utils.modifyAccount(Main.this); } } }); duplicate = new Button("Avaa ikkunassa"); duplicate2 = new Button("Avaa alas"); duplicate.setWidthUndefined(); duplicate.addStyleName(ValoTheme.BUTTON_TINY); duplicate.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { MapVis model = js2.getModel(); if (model == null) { UIState s = uiState.duplicate(Main.this); s.reference = s.current; mapDialog = new Window(s.reference.getText(database), new VerticalLayout()); mapDialog.setWidth(dialogWidth()); mapDialog.setHeight(dialogHeight()); mapDialog.setResizable(true); mapDialog.setContent(js2Container); mapDialog.setVisible(true); mapDialog.setResizeLazy(false); mapDialog.addCloseListener(new CloseListener() { @Override public void windowClose(CloseEvent e) { duplicate.setCaption("Avaa ikkunassa"); duplicate2.setVisible(true); UIState s = uiState.duplicate(Main.this); mapDialog.close(); mapDialog = null; s.reference = null; setFragment(s, true); } }); mapDialog.addResizeListener(new ResizeListener() { @Override public void windowResized(ResizeEvent e) { Updates.updateJS(Main.this, false); } }); setFragment(s, true); addWindow(mapDialog); duplicate.setCaption("Sulje referenssi"); duplicate2.setVisible(false); } else { UIState s = uiState.duplicate(Main.this); if (mapDialog != null) { mapDialog.close(); mapDialog = null; } panelLayout.removeComponent(js2Container); s.reference = null; setFragment(s, true); duplicate.setCaption("Avaa ikkunassa"); duplicate2.setVisible(true); } } }); duplicate2.setWidthUndefined(); duplicate2.addStyleName(ValoTheme.BUTTON_TINY); duplicate2.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { MapVis model = js2.getModel(); assert (model == null); UIState s = uiState.duplicate(Main.this); s.reference = s.current; setFragment(s, true); panelLayout.addComponent(js2Container); duplicate.setCaption("Sulje referenssi"); duplicate2.setVisible(false); } }); login = new Button("Kirjaudu"); login.setWidthUndefined(); login.addStyleName(ValoTheme.BUTTON_TINY); login.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { if (account != null) { account = null; hallinnoi.setVisible(false); tili.setVisible(false); Updates.update(Main.this, true); login.setCaption("Kirjaudu"); } else { Login.login(Main.this); } } }); times = new ComboBox(); times.setWidth("130px"); times.addStyleName(ValoTheme.COMBOBOX_SMALL); times.addItem(Property.AIKAVALI_KAIKKI); times.addItem("2016"); times.addItem("2017"); times.addItem("2018"); times.addItem("2019"); times.select("2016"); times.setInvalidAllowed(false); times.setNullSelectionAllowed(false); times.addValueChangeListener(timesListener); final HorizontalLayout hl0 = new HorizontalLayout(); hl0.setWidth("100%"); hl0.setHeight("32px"); hl0.setSpacing(true); hl0.addComponent(pdf); hl0.setComponentAlignment(pdf, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(pdf, 0.0f); hl0.addComponent(propertyExcelButton); hl0.setComponentAlignment(propertyExcelButton, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(propertyExcelButton, 0.0f); hl0.addComponent(states); hl0.setComponentAlignment(states, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(states, 0.0f); hl0.addComponent(saveState); hl0.setComponentAlignment(saveState, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(saveState, 0.0f); hl0.addComponent(times); hl0.setComponentAlignment(times, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(times, 0.0f); hl0.addComponent(search); hl0.setComponentAlignment(search, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(search, 1.0f); hl0.addComponent(modeLabel); hl0.setComponentAlignment(modeLabel, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(modeLabel, 0.0f); hl0.addComponent(mode); hl0.setComponentAlignment(mode, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(mode, 0.0f); hl0.addComponent(meterMode); hl0.setComponentAlignment(meterMode, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(meterMode, 0.0f); hl0.addComponent(hallinnoi); hl0.setComponentAlignment(hallinnoi, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(hallinnoi, 0.0f); hl0.addComponent(tili); hl0.setComponentAlignment(tili, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(tili, 0.0f); hl0.addComponent(duplicate); hl0.setComponentAlignment(duplicate, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(duplicate, 0.0f); hl0.addComponent(duplicate2); hl0.setComponentAlignment(duplicate2, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(duplicate2, 0.0f); hl0.addComponent(login); hl0.setComponentAlignment(login, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(login, 0.0f); propertiesPanel = new Panel(); propertiesPanel.setSizeFull(); properties = new VerticalLayout(); properties.setSpacing(true); properties.setMargin(true); propertiesPanel.setContent(properties); propertiesPanel.setVisible(false); tags = new VerticalLayout(); tags.setSpacing(true); Updates.updateTags(this); AbsoluteLayout tabs = new AbsoluteLayout(); tabs.setSizeFull(); { panel = new Panel(); panel.addStyleName(ValoTheme.PANEL_BORDERLESS); panel.setSizeFull(); panel.setId("mapContainer1"); panelLayout = new VerticalLayout(); panelLayout.addComponent(js); panelLayout.setHeight("100%"); js2Container = new VerticalLayout(); js2Container.setHeight("100%"); js2Container.addComponent(new Label("<hr />", ContentMode.HTML)); js2Container.addComponent(js2); panel.setContent(panelLayout); tabs.addComponent(panel); } wiki = new BrowserFrame(); wiki.setSource(new ExternalResource(Wiki.wikiAddress() + "/")); wiki.setWidth("100%"); wiki.setHeight("100%"); { wiki_ = new VerticalLayout(); wiki_.setSizeFull(); Button b = new Button("Palaa sovellukseen"); b.setWidth("100%"); b.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { applyFragment(backFragment, true); String content = Wiki.get(wikiPage); if (content == null) return; int first = content.indexOf("<rev contentformat"); if (first == -1) return; content = content.substring(first); int term = content.indexOf(">"); content = content.substring(term + 1); int end = content.indexOf("</rev>"); content = content.substring(0, end); if (wikiBase.modifyMarkup(Main.this, content)) { Updates.update(Main.this, true); } } }); wiki_.addComponent(b); wiki_.addComponent(wiki); wiki_.setVisible(false); wiki_.setExpandRatio(b, 0.0f); wiki_.setExpandRatio(wiki, 1.0f); tabs.addComponent(wiki_); } hs = new HorizontalSplitPanel(); hs.setSplitPosition(0, Unit.PIXELS); hs.setHeight("100%"); hs.setWidth("100%"); browser = new VerticalLayout(); browser.setSizeFull(); HorizontalLayout browserWidgets = new HorizontalLayout(); browserWidgets.setWidth("100%"); hori = new Button(); hori.setDescription("Nyt asiat taulukkona"); hori.setEnabled(true); hori.setIcon(FontAwesome.ARROW_RIGHT); hori.addStyleName(ValoTheme.BUTTON_TINY); hori.addClickListener(new ClickListener() { boolean right = false; @Override public void buttonClick(ClickEvent event) { if (right) { hs.setSplitPosition(0, Unit.PIXELS); hori.setIcon(FontAwesome.ARROW_RIGHT); hori.setDescription("Nyt asiat taulukkona"); right = false; } else { hs.setSplitPosition(windowWidth / 2, Unit.PIXELS); hori.setIcon(FontAwesome.ARROW_LEFT); hori.setDescription("Piilota taulukko"); right = true; } } }); more = new Button(); more.setDescription("Laajenna nytettvien asioiden joukkoa"); more.setIcon(FontAwesome.PLUS_SQUARE); more.addStyleName(ValoTheme.BUTTON_TINY); more.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { uiState.level++; Updates.updateJS(Main.this, false); if (uiState.level >= 2) less.setEnabled(true); } }); less = new Button(); less.setDescription("Supista nytettvien asioiden joukkoa"); less.setIcon(FontAwesome.MINUS_SQUARE); less.addStyleName(ValoTheme.BUTTON_TINY); less.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { if (uiState.level > 1) { uiState.level--; Updates.updateJS(Main.this, false); } if (uiState.level <= 1) less.setEnabled(false); } }); reportAllButton = new Button(); reportAllButton.setCaption("Nkyvt tulokset"); reportAllButton.addStyleName(ValoTheme.BUTTON_TINY); reportAllButton.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { if (uiState.reportAll) { reportAllButton.setCaption("Nkyvt tulokset"); uiState.reportAll = false; } else { reportAllButton.setCaption("Kaikki tulokset"); uiState.reportAll = true; } Updates.updateJS(Main.this, false); } }); reportStatus = new Label("0 tulosta."); reportStatus.setWidth("100px"); filter = new ComboBox(); filter.setWidth("100%"); filter.addStyleName(ValoTheme.COMBOBOX_SMALL); filter.setInvalidAllowed(false); filter.setNullSelectionAllowed(false); filter.addValueChangeListener(filterListener); browserWidgets.addComponent(hori); browserWidgets.setComponentAlignment(hori, Alignment.MIDDLE_LEFT); browserWidgets.setExpandRatio(hori, 0.0f); browserWidgets.addComponent(more); browserWidgets.setComponentAlignment(more, Alignment.MIDDLE_LEFT); browserWidgets.setExpandRatio(more, 0.0f); browserWidgets.addComponent(less); browserWidgets.setComponentAlignment(less, Alignment.MIDDLE_LEFT); browserWidgets.setExpandRatio(less, 0.0f); browserWidgets.addComponent(reportAllButton); browserWidgets.setComponentAlignment(reportAllButton, Alignment.MIDDLE_LEFT); browserWidgets.setExpandRatio(reportAllButton, 0.0f); browserWidgets.addComponent(reportStatus); browserWidgets.setComponentAlignment(reportStatus, Alignment.MIDDLE_LEFT); browserWidgets.setExpandRatio(reportStatus, 0.0f); browserWidgets.addComponent(filter); browserWidgets.setComponentAlignment(filter, Alignment.MIDDLE_LEFT); browserWidgets.setExpandRatio(filter, 1.0f); browser.addComponent(browserWidgets); browser.addComponent(hs); browser.setExpandRatio(browserWidgets, 0.0f); browser.setExpandRatio(hs, 1.0f); browser.setVisible(false); tabs.addComponent(browser); { gridPanelLayout = new VerticalLayout(); gridPanelLayout.setMargin(false); gridPanelLayout.setSpacing(false); gridPanelLayout.setSizeFull(); hs.addComponent(gridPanelLayout); } CssLayout browserLayout = new CssLayout(); browserLayout.setSizeFull(); browserLayout.addComponent(browser_); hs.addComponent(browserLayout); tabs.addComponent(propertiesPanel); vs.addComponent(hl0); vs.addComponent(tabs); vs.setExpandRatio(hl0, 0.0f); vs.setExpandRatio(tabs, 1.0f); // Ground state fragments.put("", uiState); setCurrentItem(uiState.currentItem, (Strategiakartta) uiState.currentItem); }