List of usage examples for org.apache.poi.hssf.usermodel HSSFCell setCellValue
@SuppressWarnings("fallthrough") public void setCellValue(boolean value)
From source file:FILING.childdetailsreport.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from www. ja v a 2 s . co m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException { response.setContentType("text/html;charset=UTF-8"); // PrintWriter out = response.getWriter(); try { dbConn conn = new dbConn("1"); String District = ""; District = request.getParameter("District"); String Year = ""; Year = request.getParameter("Year"); String chw = ""; String FirstName = ""; String MiddleName = ""; String Surname = ""; String ovcid1 = ""; String ovcid2 = ""; int value0 = 0; int value1 = 0; String Districtid = ""; String cboid = ""; String doc = ""; String docname = ""; String cboname = ""; String districtname = ""; String chwval = ""; String docid = ""; // ^^^^^^^^^^^^^CREATE STATIC AND WRITE STATIC DATA TO THE EXCELL^^^^^^^^^^^^ HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet shet1 = wb.createSheet(); int cbocount = 3; //%%%%%%%%%%%%%%%%HEADER FONTS AND COLORATION%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // style header with font color yello HSSFFont font_header = wb.createFont(); font_header.setFontHeightInPoints((short) 10); font_header.setFontName("Arial Black"); font_header.setItalic(true); font_header.setBoldweight((short) 05); font_header.setColor(HSSFColor.BLACK.index); CellStyle style_header = wb.createCellStyle(); style_header.setFont(font_header); style_header.setWrapText(true); style_header.setFillForegroundColor(HSSFColor.YELLOW.index); style_header.setBorderBottom(HSSFCellStyle.BORDER_THIN); style_header.setBorderTop(HSSFCellStyle.BORDER_THIN); style_header.setBorderRight(HSSFCellStyle.BORDER_THIN); style_header.setBorderLeft(HSSFCellStyle.BORDER_THIN); style_header.setAlignment(CellStyle.ALIGN_CENTER); style_header.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // stylex with font color blue and backgound grey HSSFCellStyle stylex = wb.createCellStyle(); stylex.setFillForegroundColor(HSSFColor.PALE_BLUE.index); stylex.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); HSSFFont fontx = wb.createFont(); fontx.setColor(HSSFColor.DARK_BLUE.index); stylex.setFont(fontx); stylex.setBorderBottom(HSSFCellStyle.BORDER_THIN); stylex.setBorderTop(HSSFCellStyle.BORDER_THIN); stylex.setBorderRight(HSSFCellStyle.BORDER_THIN); stylex.setBorderLeft(HSSFCellStyle.BORDER_THIN); stylex.setAlignment(CellStyle.ALIGN_CENTER); // gold bg color -style HSSFFont font = wb.createFont(); font.setFontHeightInPoints((short) 12); font.setFontName("Cambria"); font.setItalic(true); font.setBoldweight((short) 02); font.setColor(HSSFColor.BLACK.index); CellStyle style = wb.createCellStyle(); style.setFont(font); style.setWrapText(true); style.setFillForegroundColor(HSSFColor.GREY_40_PERCENT.index); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setBorderTop(HSSFCellStyle.BORDER_THIN); style.setBorderRight(HSSFCellStyle.BORDER_THIN); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); // for border with no font color CellStyle style_border = wb.createCellStyle(); style_border.setBorderBottom(HSSFCellStyle.BORDER_THIN); style_border.setBorderTop(HSSFCellStyle.BORDER_THIN); style_border.setBorderRight(HSSFCellStyle.BORDER_THIN); style_border.setBorderLeft(HSSFCellStyle.BORDER_THIN); HSSFFont font1 = wb.createFont(); font1.setFontHeightInPoints((short) 18); font1.setFontName("Cambria"); font1.setBoldweight((short) 7); font1.setColor(HSSFColor.BLACK.index); CellStyle style_border1 = wb.createCellStyle(); style_border1.setBorderBottom(HSSFCellStyle.BORDER_THIN); style_border1.setBorderTop(HSSFCellStyle.BORDER_THIN); style_border1.setBorderRight(HSSFCellStyle.BORDER_THIN); style_border1.setBorderLeft(HSSFCellStyle.BORDER_THIN); style_border1.setFont(font); style_border1.setAlignment(CellStyle.ALIGN_CENTER); style_border1.setVerticalAlignment(CellStyle.ALIGN_LEFT); HSSFRow rw1 = shet1.createRow(1); rw1.setHeightInPoints(30); for (int y = 0; y < 11; ++y) { HSSFCell cell = rw1.createCell(y); cell.setCellStyle(stylex); if (y == 0) { cell.setCellValue("OVC DOCUMENT DETAILS REPORT"); } } shet1.addMergedRegion(new CellRangeAddress(1, 1, 0, 11)); shet1.setColumnWidth(0, 9000); shet1.setColumnWidth(1, 9000); shet1.setColumnWidth(2, 9000); shet1.setColumnWidth(3, 9000); shet1.setColumnWidth(4, 5000); shet1.setColumnWidth(5, 5000); shet1.setColumnWidth(6, 5000); shet1.setColumnWidth(7, 5000); shet1.setColumnWidth(8, 5000); shet1.setColumnWidth(9, 5000); shet1.setColumnWidth(10, 5000); shet1.setColumnWidth(11, 5000); shet1.setColumnWidth(12, 5000); shet1.setColumnWidth(13, 5000); // Merge the cells // shet1.addMergedRegion(new CellRangeAddress(1,1,1,3)); HSSFRow rw4 = shet1.createRow(2); rw4.setHeightInPoints(50); HSSFRow rw6 = shet1.createRow(3); rw6.setHeightInPoints(25); // rw4.setRowStyle(style); // // // rw6.setRowStyle(style); // // rw4.createCell(1).setCellValue("Number"); HSSFCell cell1, cell0, cell2, cell3, cell4, cell5, cell6, cell7, cell8, cell9, cell10, cell11, cell12, cell13, cell14, cell15, cell16; // cells fo row 2 cell0 = rw4.createCell(0); cell1 = rw4.createCell(1); cell2 = rw4.createCell(2); cell4 = rw4.createCell(3); cell0.setCellValue("CBO"); cell0.setCellStyle(style); cell1.setCellValue("CHW"); cell1.setCellStyle(style); cell2.setCellValue("OVCID"); cell2.setCellStyle(style); cell4.setCellValue("FULLNAME"); cell4.setCellStyle(style); ArrayList docidarray = new ArrayList(); int rowcount = 3; int doccounter = 3; int doccounter1 = 4; int columcounter = 3; String cboids = ""; int mergecounter = 2; String getdocname = "select * from ovcdocuments WHERE DocumentName!=''"; conn.rs3 = conn.state3.executeQuery(getdocname); while (conn.rs3.next()) { System.out.println(conn.rs3.getString(2)); docname = conn.rs3.getString(2); cell3 = rw4.createCell(doccounter1); cell3.setCellValue(docname); cell3.setCellStyle(style); docidarray.add(conn.rs3.getString(1)); doccounter1++; } System.out.println("lll " + doccounter1); int rowcounter = 4; int counter = 0; int countercopy = 3; int countercopy1 = 3; HSSFRow rw5 = null; String getcboCOUNT = "select * from CBO where DistrictID='" + District + "' Order by DistrictID "; conn.rs2 = conn.state2.executeQuery(getcboCOUNT); while (conn.rs2.next()) { counter++; System.out.println("bb b " + conn.rs2.getString(2)); System.out.println("rowcount " + rowcount + " lll " + counter + " rowcounter " + rowcounter); System.out.println("doccount " + doccounter); String getData = "select " + "ovcfiling.value,Clientdetails.FirstName, Middlename,SurName,ovcfiling.OVCID" + " , Clientdetails.Cbo," + "ovcfiling.ovcdocid,Clientdetails.District,Clientdetails.Volunteerid " + " from ovcfiling,Clientdetails " + "WHERE Clientdetails.District ='" + District + "' and Clientdetails.Cbo='" + conn.rs2.getString(1) + "' " + "and Clientdetails.OVCID = ovcfiling.ovcid and (Year='" + Year + "' OR Year='') " + "group by Clientdetails.FirstName, Middlename,Surname,ovcfiling.OVCID,Clientdetails.Volunteerid,ovcfiling.value,ovcfiling.ovcdocid,Clientdetails.Cbo,Clientdetails.District " + "Order by Clientdetails.Volunteerid,ovcfiling.OVCID,ovcfiling.ovcdocid"; System.out.println("aaaaa " + getData); conn.rs = conn.state.executeQuery(getData); while (conn.rs.next()) { value1 = conn.rs.getInt(1); FirstName = conn.rs.getString(2); MiddleName = conn.rs.getString(3); Surname = conn.rs.getString(4); ovcid1 = conn.rs.getString(5); // String getcbo= "select * from CBO where CBOID='"+cboid+"' "; // System.out.println("aaa "+getcbo); // conn.rs_1= conn.state4.executeQuery(getcbo); // while(conn.rs_1.next()){ //// // cbocount++; // cboname=conn.rs_1.getString("CBO"); // System.out.println("aaab "+cboname); // } cboname = conn.rs2.getString(2); cboid = conn.rs.getString(6); docid = conn.rs.getString(7); String getchw = "select * from CHW where CHWID='" + conn.rs.getString(9) + "' "; conn.rs3 = conn.state3.executeQuery(getchw); while (conn.rs3.next()) { chw = conn.rs3.getString("FirstName") + " " + conn.rs3.getString("MiddleName") + " " + conn.rs3.getString("Surname") + " " + conn.rs3.getString("CBOID"); } // fro holding ovc id // to create rows if (docid.equals("1")) { rw5 = shet1.createRow(rowcount); rw5.setHeightInPoints(25); for (int i = 2; i < doccounter1; i++) { System.out.println("mm " + i); cell5 = rw5.createCell(i); cell5.setCellValue(""); cell5.setCellStyle(style_border1); } rowcount++; cbocount++; } cell1 = rw5.createCell(0); cell1.setCellValue(cboname); cell1.setCellStyle(style_border1); cell1 = rw5.createCell(1); cell1.setCellValue(chw); cell1.setCellStyle(style_border1); cell1 = rw5.createCell(2); cell1.setCellValue(ovcid1); cell1.setCellStyle(style_border1); cell1 = rw5.createCell(3); cell1.setCellValue(FirstName + " " + MiddleName + " " + Surname); cell1.setCellStyle(style_border1); for (int i = 0; i < docidarray.size(); i++) { System.out.println("hh " + docidarray.get(i)); if (rw5 == null) { rw5 = shet1.createRow(rowcount); } if (docidarray.get(i).equals(docid)) { int cellcount = i + 4; cell2 = rw5.createCell(cellcount); cell2.setCellValue(value1); cell2.setCellStyle(style_border1); // if( docid.equals("3") ) { // System.out.println("am in2"); // System.out.println("****a "+docid +" "+cellcount); // cellcount++; // } System.out.println("****b " + docid + " " + cellcount); } } // cell3=rw5.createCell(2); // cell3.setCellValue(docid); // cell3.setCellStyle(style_border1); System.out.println( FirstName + " " + ovcid1 + " " + value1 + "___" + doccounter + "_____" + rowcount); if (docid.equals("10")) { // rowcount++; doccounter = 2; } if (chwval.equals("")) { chwval = chw; System.out.println(countercopy + " nnnna " + rowcount); // shet1.addMergedRegion(new CellRangeAddress(countercopy,rowcount-1,0,0)); // countercopy=rowcount; System.out.println(countercopy + " nnnnb " + rowcount + " " + chwval); } if (!chwval.equals(chw) && !chwval.equals("")) { chwval = chw; System.out.println(countercopy + " nnna" + rowcount + " " + chwval); shet1.addMergedRegion(new CellRangeAddress(countercopy, rowcount - 2, 1, 1)); countercopy = rowcount - 1; System.out.println(countercopy + " nnnb " + rowcount + " " + chwval); } String cboval = ""; if (cboval.equals("")) { cboval = cboname; // shet1.addMergedRegion(new CellRangeAddress(countercopy1,cbocount-1,0,0)); // countercopy1=cbocount; } if (!cboval.equals(cboname) && !cboval.equals("")) { cboval = cboname; System.out.println(countercopy1 + " nnna" + cbocount + " " + chwval); shet1.addMergedRegion(new CellRangeAddress(countercopy1, cbocount - 2, 0, 0)); countercopy1 = cbocount - 1; System.out.println(countercopy1 + " nnnb " + rowcount + " " + cboval); } // // if(monthval.equals("")){ // monthval= months; // System.out.println("88"+monthval +"___"+months); // System.out.println("88"+monthcopy1); // System.out.println("88"+counter1); // cell31.setCellValue(""+months+ " ("+conn.rs3.getInt(5)+")"); // shet2.addMergedRegion(new CellRangeAddress(monthcopy_1,counter1-1,1,1)); // monthcopy1=counter1; // // } // if(!monthval.equals("") && !monthval.equals(months)){ // monthval= months; // System.out.println("!!!"+monthval +"___"+months); // System.out.println("!!!"+monthcopy_1); // System.out.println("!!!!"+counter1); //// cell31.setCellValue(months); //// shet1.addMergedRegion(new CellRangeAddress(monthcopy,counter-1,1,1)); // monthcopy_1=counter1; // // } // if(rowcount>countercopy) { // // shet1.addMergedRegion(new CellRangeAddress(countercopy,rowcount-1,0,0)); // countercopy=rowcount; // } } if (rowcount > countercopy) { shet1.addMergedRegion(new CellRangeAddress(countercopy, rowcount - 1, 1, 1)); countercopy = rowcount; } if (cbocount > countercopy1) { shet1.addMergedRegion(new CellRangeAddress(countercopy1, cbocount - 1, 0, 0)); countercopy1 = cbocount; } //} System.out.println("aaaaaa " + districtname + "__" + cboname + "____" + docname + "___" + value1 + "__" + value0); } // // end of while loop ByteArrayOutputStream outByteStream = new ByteArrayOutputStream(); wb.write(outByteStream); byte[] outArray = outByteStream.toByteArray(); response.setContentType("application/ms-excel"); response.setContentLength(outArray.length); response.setHeader("Expires:", "0"); // eliminates browser caching response.setHeader("Content-Disposition", "attachment; filename=CBO_Details_Report_" + Year + ".xls"); OutputStream outStream = response.getOutputStream(); outStream.write(outArray); outStream.flush(); } finally { // out.close(); } }
From source file:FILING.countyreport.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w ww . j a va2s. co m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException { response.setContentType("text/html;charset=UTF-8"); // PrintWriter out = response.getWriter(); try { dbConn conn = new dbConn("1"); String County[]; County = request.getParameterValues("County"); String Year = ""; Year = request.getParameter("Year"); float percent = 0; ArrayList docidarray = new ArrayList(); System.out.println("countyv " + County); String FirstName = ""; String MiddleName = ""; String Surname = ""; String ovcid1 = ""; String ovcid2 = ""; int value0 = 0; int value1 = 0; String Districtid = ""; String cboid = ""; String doc = ""; String docname = ""; String cboname = ""; String districtname = ""; String countyval = ""; int countercopy = 4; int activeOVC = 0; int activeHH = 0; // ^^^^^^^^^^^^^CREATE STATIC AND WRITE STATIC DATA TO THE EXCELL^^^^^^^^^^^^ HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet shet1 = wb.createSheet(); //%%%%%%%%%%%%%%%%HEADER FONTS AND COLORATION%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // style header with font color yello HSSFFont font_header = wb.createFont(); font_header.setFontHeightInPoints((short) 10); font_header.setFontName("Arial Black"); font_header.setItalic(true); font_header.setBoldweight((short) 05); font_header.setColor(HSSFColor.BLACK.index); CellStyle style_header = wb.createCellStyle(); style_header.setFont(font_header); style_header.setWrapText(true); style_header.setFillForegroundColor(HSSFColor.YELLOW.index); style_header.setBorderBottom(HSSFCellStyle.BORDER_THIN); style_header.setBorderTop(HSSFCellStyle.BORDER_THIN); style_header.setBorderRight(HSSFCellStyle.BORDER_THIN); style_header.setBorderLeft(HSSFCellStyle.BORDER_THIN); style_header.setAlignment(CellStyle.ALIGN_CENTER); style_header.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // stylex with font color blue and backgound grey HSSFCellStyle stylex = wb.createCellStyle(); stylex.setFillForegroundColor(HSSFColor.PALE_BLUE.index); stylex.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); HSSFFont fontx = wb.createFont(); fontx.setColor(HSSFColor.DARK_BLUE.index); stylex.setFont(fontx); stylex.setBorderBottom(HSSFCellStyle.BORDER_THIN); stylex.setBorderTop(HSSFCellStyle.BORDER_THIN); stylex.setBorderRight(HSSFCellStyle.BORDER_THIN); stylex.setBorderLeft(HSSFCellStyle.BORDER_THIN); stylex.setAlignment(CellStyle.ALIGN_CENTER); // gold bg color -style HSSFFont font = wb.createFont(); font.setFontHeightInPoints((short) 12); font.setFontName("Cambria"); font.setItalic(true); font.setBoldweight((short) 02); font.setColor(HSSFColor.BLACK.index); CellStyle style = wb.createCellStyle(); style.setFont(font); style.setWrapText(true); style.setFillForegroundColor(HSSFColor.GREY_40_PERCENT.index); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setBorderTop(HSSFCellStyle.BORDER_THIN); style.setBorderRight(HSSFCellStyle.BORDER_THIN); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); // for border with no font color CellStyle style_border = wb.createCellStyle(); style_border.setBorderBottom(HSSFCellStyle.BORDER_THIN); style_border.setBorderTop(HSSFCellStyle.BORDER_THIN); style_border.setBorderRight(HSSFCellStyle.BORDER_THIN); style_border.setBorderLeft(HSSFCellStyle.BORDER_THIN); HSSFFont font1 = wb.createFont(); font1.setFontHeightInPoints((short) 18); font1.setFontName("Cambria"); font1.setBoldweight((short) 7); font1.setColor(HSSFColor.BLACK.index); CellStyle style_border1 = wb.createCellStyle(); style_border1.setBorderBottom(HSSFCellStyle.BORDER_THIN); style_border1.setBorderTop(HSSFCellStyle.BORDER_THIN); style_border1.setBorderRight(HSSFCellStyle.BORDER_THIN); style_border1.setBorderLeft(HSSFCellStyle.BORDER_THIN); style_border1.setFont(font); style_border1.setAlignment(CellStyle.ALIGN_JUSTIFY); style_border1.setVerticalAlignment(CellStyle.ALIGN_LEFT); HSSFRow rw1 = shet1.createRow(1); //cell; rw1.setHeightInPoints(30); for (int y = 0; y < 11; ++y) { HSSFCell cell = rw1.createCell(y); cell.setCellStyle(stylex); if (y == 0) { cell.setCellValue("COUNTY FILING TRACKER REPORT " + Year); } } shet1.addMergedRegion(new CellRangeAddress(1, 1, 0, 11)); shet1.setColumnWidth(0, 4500); shet1.setColumnWidth(1, 8500); shet1.setColumnWidth(2, 5000); shet1.setColumnWidth(3, 5000); shet1.setColumnWidth(4, 5000); shet1.setColumnWidth(5, 5000); shet1.setColumnWidth(6, 5000); shet1.setColumnWidth(7, 5000); shet1.setColumnWidth(8, 5000); shet1.setColumnWidth(9, 5000); shet1.setColumnWidth(10, 5000); shet1.setColumnWidth(11, 5000); shet1.setColumnWidth(12, 5000); shet1.setColumnWidth(13, 5000); shet1.setColumnWidth(14, 5000); shet1.setColumnWidth(15, 5000); shet1.setColumnWidth(16, 5000); shet1.setColumnWidth(17, 5000); shet1.setColumnWidth(18, 5000); shet1.setColumnWidth(19, 5000); shet1.setColumnWidth(20, 4500); shet1.setColumnWidth(21, 4500); shet1.setColumnWidth(22, 3500); // Merge the cells // shet1.addMergedRegion(new CellRangeAddress(1,1,1,3)); HSSFRow rw4 = shet1.createRow(2); rw4.setHeightInPoints(40); HSSFRow rw6 = shet1.createRow(3); rw6.setHeightInPoints(25); // rw4.setRowStyle(style); // // // rw6.setRowStyle(style); // // rw4.createCell(1).setCellValue("Number"); HSSFCell cell1, cell2, cell3, cell4, cell5, cell6, cell7, cell8, cell9, cell10, cell11, cell12, cell13, cell14, cell15, cell16; // cells fo row 2 cell1 = rw4.createCell(0); cell2 = rw4.createCell(1); cell4 = rw4.createCell(3); cell1.setCellValue("COUNTY"); cell1.setCellStyle(style); cell2.setCellValue("DISTRICT"); cell2.setCellStyle(style); cell6 = rw6.createCell(0); cell6.setCellValue("Status"); cell6.setCellStyle(style); cell7 = rw6.createCell(1); cell7.setCellValue(""); cell7.setCellStyle(style_header); cell3 = rw4.createCell(2); cell3.setCellValue("ACTIVE OVC"); cell3.setCellStyle(style); cell3 = rw4.createCell(3); cell3.setCellValue("ACTIVE HH"); cell3.setCellStyle(style); shet1.addMergedRegion(new CellRangeAddress(3, 3, 0, 1)); int rowcount = 3; int doccounter = 4; int doccounter1 = 4; int columcounter = 3; String cboids = ""; int mergecounter = 2; cell6 = rw6.createCell(2); cell6.setCellValue(""); cell6.setCellStyle(stylex); cell6 = rw6.createCell(3); cell6.setCellValue(""); cell6.setCellStyle(stylex); String getdocname = "select * from ovcdocuments where DocumentName!=''"; conn.rs3 = conn.state3.executeQuery(getdocname); while (conn.rs3.next()) { System.out.println("mmm " + doccounter1); System.out.println(conn.rs3.getString(2)); docname = conn.rs3.getString(2); cell3 = rw4.createCell(doccounter1); cell3.setCellValue(docname); cell3.setCellStyle(style); docidarray.add(conn.rs3.getString(1)); cell6 = rw6.createCell(doccounter1++); cell6.setCellValue("Available"); cell6.setCellStyle(stylex); // cell5=rw6.createCell(doccounter1); // cell5.setCellValue("Not Available"); // cell5.setCellStyle(stylex); // doccounter1++; // System.out.println("mergecounter b4"+mergecounter); // System.out.println("mergecounter after"+mergecounter); // mergecounter++; //shet1.addMergedRegion(new CellRangeAddress(2,2,doccounter1,doccounter1++)); } System.out.println("lll " + doccounter1); int rowcounter = 4; int counter = 0; HSSFRow rw5 = null; String DistrictID = ""; for (int j = 0; j < County.length; j++) { String getDistrictCounts = "select * from District where Countyid='" + County[j] + "' order by District"; System.out.println("districtID " + getDistrictCounts); conn.rs2 = conn.state2.executeQuery(getDistrictCounts); while (conn.rs2.next()) { System.out.println("district1" + conn.rs2.getString("District")); counter++; rowcount++; rw5 = shet1.createRow(rowcount); for (int i = 2; i < doccounter1; i++) { System.out.println("mm " + i); cell5 = rw5.createCell(i); cell5.setCellValue(""); cell5.setCellStyle(style_border1); } cell2 = rw5.createCell(1); cell2.setCellValue(conn.rs2.getString(2)); cell2.setCellStyle(style_border); // cell5=rw5.createCell(rowcount); // cell6=rw5.createCell(rowcounter++); // cell5.setCellValue("x"); // cell6.setCellValue("y"); System.out.println("rowcount " + rowcount + " lll " + counter + " rowcounter " + rowcounter); rw5.setHeightInPoints(25); // cell3=rw5.createCell(2); String getDistrict = "select * from County where CountyID='" + County[j] + "' order by County"; System.out.println("dname " + getDistrict); conn.rs4 = conn.state4.executeQuery(getDistrict); while (conn.rs4.next()) { districtname = conn.rs4.getString("County"); System.out.println("district2" + districtname); cell1 = rw5.createCell(0); cell1.setCellValue(districtname); cell1.setCellStyle(style_border1); // to marge these values } System.out.println("doccount " + doccounter); doccounter = 4; String getData = "select " + "SUM(CASE WHEN ovcfiling.value='1' THEN 1 ELSE 0 END) AS COUNT1, " + "SUM(CASE WHEN ovcfiling.value='0' THEN 1 ELSE 0 END) AS COUNT0," + "Clientdetails.Cbo," + "ovcfiling.ovcdocid,Clientdetails.District, " + "count(Clientdetails.OVCID)," + "count(DISTINCT(Clientdetails.HouseHoldheadID))" + " from ovcfiling,Clientdetails " + "WHERE Clientdetails.District ='" + conn.rs2.getString("DistrictID") + "' and Clientdetails.OVCID = ovcfiling.ovcid and Clientdetails.Exited='1' and (Year='" + Year + "' OR Year='') " + "group by ovcfiling.ovcdocid,Clientdetails.Cbo,Clientdetails.District order by Clientdetails.District,ovcfiling.ovcdocid"; System.out.println("aaaaa " + getData); conn.rs = conn.state.executeQuery(getData); while (conn.rs.next()) { value1 = conn.rs.getInt(1); value0 = conn.rs.getInt(2); cboid = conn.rs.getString(3); doc = conn.rs.getString(4); Districtid = conn.rs.getString(5); activeOVC = conn.rs.getInt(6); activeHH = conn.rs.getInt(7); System.out.println("district3 " + Districtid); float activeovc = 0; float activehh = 0; for (int i = 0; i < docidarray.size(); i++) { System.out.println("hh " + docidarray.get(i) + " " + doc); // if(rw5==null){ // rw5=shet1.createRow(rowcount); // } if (docidarray.get(i).equals(doc)) { System.out.println(doc + "lll" + docidarray.get(i)); int cellcount = i + 2; // cell2=rw5.createCell(cellcount++); // cell2.setCellValue(value1); // cell2.setCellStyle(style_border1); // String getdocname1="select * from ovcdocuments"; // conn.rs3= conn.state3.executeQuery(getdocname1); // if(conn.rs3.next()){ cell7 = rw5.createCell(2); cell8 = rw5.createCell(3); cell5 = rw5.createCell(doccounter); // cell6=rw5.createCell(doccounter); activeovc = activeOVC; activehh = activeHH; if (doc.equals("8")) { percent = value1 / activehh * 100; } else { percent = value1 / activeovc * 100; } System.out.println("percenta " + percent + " " + value1 + " " + activeOVC + " act " + activeovc); cell5.setCellValue(Math.round(percent) + "%"); // cell6.setCellValue(value0); //FOR ACTICE OVCs cell7.setCellValue(activeOVC); cell7.setCellStyle(style_border); //FOR ACTICE hhs cell8.setCellValue(activeHH); cell8.setCellStyle(style_border); cell5.setCellStyle(style_border); cell6.setCellStyle(style_border); System.out.println("****a " + doc + " " + doccounter); if (doc.equals("2")) { // System.out.println("****i "+doc +" "+doccounter); doccounter++; // doccounter++; System.out.println("am in2"); System.out.println("****b " + doc + " " + doccounter); } if (doc.equals("3")) { percent = value1 / activeovc * 100; doccounter--; // doccounter--; // doccounter--; System.out.println("****f " + doc + " " + doccounter); cell5 = rw5.createCell(doccounter++); cell5.setCellStyle(style_border); cell5.setCellValue(percent); cell6 = rw5.createCell(doccounter); // cell6.setCellStyle(style_border); // cell6.setCellValue(value0); System.out.println("****b " + doc + " " + doccounter); doccounter--; } // else if(!doc.equals("4") && !docidarray.get(i).equals("4")){ // doccounter++; // doccounter++; // System.out.println("****c "+doc +" "+doccounter); // } doccounter++; } } } doccounter = 2; // String getcbo= "select * from CBO where cboid='"+cboid+"'"; // conn.rs2 = conn.state2.executeQuery(getcbo); // while(conn.rs2.next()){ // // cell2=rw5.createCell(1); // cell2.setCellValue(conn.rs2.getString(2)); // // System.out.println("rowcount "+rowcount ); // // } //} System.out.println("aaaaaa " + districtname + "__" + cboname + "____" + docname + "___" + value1 + "__" + value0); // shet1.addMergedRegion(new CellRangeAddress(countercopy,counter,0,0)); // countercopy=counter; // cell1.setCellValue(districtname); } if (countyval.equals("")) { // totalvalue= countercopy+counter; System.out.println(countercopy + " counter " + counter + " " + rowcount); countyval = districtname; System.out.println(countercopy + " nnnn " + counter + " " + rowcount); // if(counter>countercopy){ shet1.addMergedRegion(new CellRangeAddress(countercopy, rowcount, 0, 0)); countercopy = rowcount; //cell1.setCellValue(districtname); // } System.out.println(countercopy + " nnn " + counter + " " + rowcount + " " + countyval); } // cell1.setCellValue(districtname); if (!countyval.equals(districtname) && !countyval.equals("")) { countyval = districtname; // cell1.setCellValue(districtname); shet1.addMergedRegion(new CellRangeAddress(countercopy + 1, rowcount, 0, 0)); countercopy = rowcount; // System.out.println(counter + "@@@@1 " + rowcount + "__" + countercopy); System.out.println(countyval + "@@@@1 " + districtname); } System.out.println(counter + "@@@@ " + rowcount); //shet1.addMergedRegion(new CellRangeAddress(counter,rowcount,0,0)); System.out.println(countyval + "@@@@ " + districtname); } System.out.println(counter + "@@@@2 " + rowcount + " copy "); // System.out.println("aaaaaannnn "+districtname+"__"+ cboname +"____"+ doc +"___"+value1 +"__"+value0 ); // write it as an excel attachment ByteArrayOutputStream outByteStream = new ByteArrayOutputStream(); wb.write(outByteStream); byte[] outArray = outByteStream.toByteArray(); response.setContentType("application/ms-excel"); response.setContentLength(outArray.length); response.setHeader("Expires:", "0"); // eliminates browser caching response.setHeader("Content-Disposition", "attachment; filename=County_Filing_Tracker_Report_" + Year + ".xls"); OutputStream outStream = response.getOutputStream(); outStream.write(outArray); outStream.flush(); } finally { // out.close(); } }
From source file:forms.SrmHome.SrmAdministration.java
/** * excel/* ww w . ja v a2 s . c o m*/ * @param mapRequest * @param mapResponse * @throws Exception */ public void exportExcel(Map mapRequest, Map mapResponse) throws Exception { HttpServletResponse response; OutputStream outStream = null; String zb_header_id = FormUtil.getStr("id", mapRequest); Map map = new HashMap(); map.put("zb_header_id", zb_header_id); try { List<CUX_PON_ZB_HEADERS_ALL> ponHeaders = zbService.getPonZbHeadersAllById(map); //?????excel if (ponHeaders != null && ponHeaders.size() > 0) { HSSFWorkbook wb = new HSSFWorkbook();// HSSFSheet sheet = null; HSSFCellStyle style = wb.createCellStyle(); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); style.setBorderRight(HSSFCellStyle.BORDER_THIN); style.setBorderTop(HSSFCellStyle.BORDER_THIN); sheet = wb.createSheet(); //? //??Excel HSSFRow rowTable = sheet.createRow(0);//? rowTable.createCell((short) 0).setCellValue(new HSSFRichTextString("??")); rowTable.createCell((short) 1).setCellValue(new HSSFRichTextString("?")); rowTable.createCell((short) 2).setCellValue(new HSSFRichTextString("??")); rowTable.createCell((short) 3).setCellValue(new HSSFRichTextString("?")); rowTable.createCell((short) 4).setCellValue(new HSSFRichTextString("??")); rowTable.createCell((short) 5).setCellValue(new HSSFRichTextString("?")); rowTable.createCell((short) 6).setCellValue(new HSSFRichTextString("?BYD")); rowTable.createCell((short) 7).setCellValue(new HSSFRichTextString("?")); rowTable.createCell((short) 8).setCellValue(new HSSFRichTextString("")); // rowTable.createCell((short) 9).setCellValue(new HSSFRichTextString("")); //?? int START_ROW_NUMBER = 1;//2?? for (int i = 0; i < ponHeaders.size(); i++) { CUX_PON_ZB_HEADERS_ALL pon = ponHeaders.get(i); //?? HSSFRow rowIndex = sheet.createRow(START_ROW_NUMBER + i); HSSFCell zb_project_description = rowIndex.createCell((short) 0); zb_project_description.setCellStyle(style); zb_project_description.setCellValue(new HSSFRichTextString(pon.getZb_project_description()));//?? HSSFCell zb_project_no = rowIndex.createCell((short) 1); zb_project_no.setCellStyle(style); zb_project_no.setCellValue(new HSSFRichTextString(pon.getZb_project_no()));//? HSSFCell description = rowIndex.createCell((short) 2); description.setCellStyle(style); description.setCellValue(new HSSFRichTextString(pon.getDescription()));//?? HSSFCell contactor = rowIndex.createCell((short) 3); contactor.setCellStyle(style); contactor.setCellValue(new HSSFRichTextString(pon.getContactor()));//? HSSFCell tel = rowIndex.createCell((short) 4); tel.setCellStyle(style); tel.setCellValue(new HSSFRichTextString(pon.getTel()));//?? HSSFCell mail = rowIndex.createCell((short) 5); mail.setCellStyle(style); mail.setCellValue(new HSSFRichTextString(pon.getMail()));//? HSSFCell status = rowIndex.createCell((short) 6); status.setCellStyle(style); status.setCellValue(new HSSFRichTextString(pon.getStatus()));//?BYD HSSFCell item_type = rowIndex.createCell((short) 7); item_type.setCellStyle(style); item_type.setCellValue(new HSSFRichTextString(pon.getItem_type()));//? HSSFCell memo = rowIndex.createCell((short) 8); memo.setCellStyle(style); memo.setCellValue(new HSSFRichTextString(pon.getMemo()));// // HSSFCell attachemnt = rowIndex.createCell((short) 9); // attachemnt.setCellStyle(style); // attachemnt.setCellValue(new HSSFRichTextString(""));// } response = ActionContext.getResponse(); response.reset(); response.setContentType("application/vnd.ms-excel;charset=utf-8"); response.setHeader("Content-Disposition", "attachment;Filename=applicationform.xls");//?? response.setHeader("Pragma", "public"); response.setHeader("Cache-Control", "max-age=30"); outStream = response.getOutputStream();//? wb.write(outStream);// ?? } } finally { if (outStream != null) { outStream.close(); } } // return null; }
From source file:fr.amapj.service.engine.generator.excel.samples.AutoSizeHeightForRow1.java
License:Open Source License
private static HSSFRow addRow(HSSFSheet sheet, HSSFCellStyle style, short rowNumber) { ///*from w ww. j a v a2s . com*/ HSSFRow row = sheet.createRow(rowNumber); // row.setRowStyle(style); -- has no effect // row.setHeight((short)-1); -- has no effect HSSFCell c = row.createCell(0); c.setCellStyle(style); c.setCellValue("x"); c = row.createCell(1); c.setCellStyle(style); c.setCellValue("a\nb\nc"); c = row.createCell(2); c.setCellStyle(style); c.setCellValue("y"); return row; }
From source file:fr.amapj.service.engine.generator.excel.samples.DiagonalBorder.java
License:Open Source License
private HSSFRow addRow(HSSFSheet sheet, HSSFCellStyle style, short rowNumber) { ///*w w w .ja v a2s . c om*/ HSSFRow row = sheet.createRow(rowNumber); HSSFCell c = row.createCell(0); c.setCellStyle(style); c.setCellValue(4.0); c = row.createCell(1); c.setCellStyle(style); c.setCellValue(4.0); c = row.createCell(2); c.setCellStyle(style); c.setCellValue(""); return row; }
From source file:fr.univlorraine.mondossierweb.controllers.ListeInscritsController.java
License:Apache License
/** * crer le fichier excel partir de la liste des inscrits. * @return le fichier excel de la liste des inscrits. *//*w w w . ja v a 2 s. c o m*/ @SuppressWarnings("deprecation") public HSSFWorkbook creerExcel(List<Inscrit> listeInscrits, List<String> listeCodInd, ComboBox listeGroupes, boolean isTraiteEtape) { // creation du fichier excel HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("page1"); boolean isSession1 = true; boolean isSession2 = true; //formatage de la taille des colonne sheet.setColumnWidth((short) 0, (short) (4000)); sheet.setColumnWidth((short) 1, (short) (6000)); sheet.setColumnWidth((short) 2, (short) (5120)); sheet.setColumnWidth((short) 3, (short) (4000)); sheet.setColumnWidth((short) 4, (short) (8000)); if (isTraiteEtape) { sheet.setColumnWidth((short) 5, (short) (1200)); sheet.setColumnWidth((short) 6, (short) (2000)); sheet.setColumnWidth((short) 7, (short) (3000)); sheet.setColumnWidth((short) 8, (short) (2000)); sheet.setColumnWidth((short) 9, (short) (3000)); } else { sheet.setColumnWidth((short) 5, (short) (2000)); sheet.setColumnWidth((short) 6, (short) (3000)); sheet.setColumnWidth((short) 7, (short) (8000)); sheet.setColumnWidth((short) 8, (short) (2000)); sheet.setColumnWidth((short) 9, (short) (3000)); sheet.setColumnWidth((short) 10, (short) (2000)); sheet.setColumnWidth((short) 11, (short) (3000)); sheet.setColumnWidth((short) 12, (short) (8000)); } // Creation des lignes HSSFRow row = sheet.createRow((short) 0); //CREATION DES STYLES: //STYLE1: HSSFCellStyle headerStyle = wb.createCellStyle(); headerStyle.setFillBackgroundColor(HSSFColor.BLUE.index); headerStyle.setFillForegroundColor(HSSFColor.BLUE.index); headerStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); HSSFFont font = wb.createFont(); font.setColor(HSSFColor.WHITE.index); font.setBoldweight((short) 10); headerStyle.setFont(font); //bordure style1 headerStyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM); headerStyle.setBottomBorderColor(HSSFColor.BLACK.index); headerStyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM); headerStyle.setLeftBorderColor(HSSFColor.BLACK.index); headerStyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM); headerStyle.setRightBorderColor(HSSFColor.BLACK.index); headerStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM); headerStyle.setTopBorderColor(HSSFColor.BLACK.index); int rang_cellule = 0; HSSFCell cellLib1 = row.createCell((short) rang_cellule); cellLib1.setCellStyle(headerStyle); cellLib1.setCellValue(applicationContext.getMessage("xls.folder", null, Locale.getDefault()).toUpperCase()); rang_cellule++; HSSFCell cellLib2 = row.createCell((short) rang_cellule); cellLib2.setCellStyle(headerStyle); cellLib2.setCellValue(applicationContext.getMessage("xls.nom", null, Locale.getDefault()).toUpperCase()); rang_cellule++; HSSFCell cellLib3 = row.createCell((short) rang_cellule); cellLib3.setCellStyle(headerStyle); cellLib3.setCellValue(applicationContext.getMessage("xls.prenom", null, Locale.getDefault()).toUpperCase()); rang_cellule++; HSSFCell cellLib4 = row.createCell((short) rang_cellule); cellLib4.setCellStyle(headerStyle); cellLib4.setCellValue( applicationContext.getMessage("xls.naissance", null, Locale.getDefault()).toUpperCase()); rang_cellule++; HSSFCell cellLib5 = row.createCell((short) rang_cellule); cellLib5.setCellStyle(headerStyle); cellLib5.setCellValue( applicationContext.getMessage("xls.messagerie", null, Locale.getDefault()).toUpperCase()); rang_cellule++; if (isTraiteEtape) { HSSFCell cellLib6 = row.createCell((short) rang_cellule); cellLib6.setCellStyle(headerStyle); cellLib6.setCellValue( applicationContext.getMessage("xls.iae", null, Locale.getDefault()).toUpperCase() + "?"); rang_cellule++; } if (!isTraiteEtape) { HSSFCell cellLib7 = row.createCell((short) rang_cellule); cellLib7.setCellStyle(headerStyle); cellLib7.setCellValue( applicationContext.getMessage("xls.code", null, Locale.getDefault()).toUpperCase()); rang_cellule++; HSSFCell cellLib8 = row.createCell((short) rang_cellule); cellLib8.setCellStyle(headerStyle); cellLib8.setCellValue( applicationContext.getMessage("xls.version", null, Locale.getDefault()).toUpperCase()); rang_cellule++; HSSFCell cellLib9 = row.createCell((short) rang_cellule); cellLib9.setCellStyle(headerStyle); cellLib9.setCellValue( applicationContext.getMessage("xls.etape", null, Locale.getDefault()).toUpperCase()); rang_cellule++; } if (isSession1) { HSSFCell cellLib10 = row.createCell((short) rang_cellule); cellLib10.setCellStyle(headerStyle); cellLib10.setCellValue( applicationContext.getMessage("xls.note1", null, Locale.getDefault()).toUpperCase()); rang_cellule++; HSSFCell cellLib11 = row.createCell((short) rang_cellule); cellLib11.setCellStyle(headerStyle); cellLib11.setCellValue( applicationContext.getMessage("xls.result1", null, Locale.getDefault()).toUpperCase()); rang_cellule++; } if (isSession2) { HSSFCell cellLib12 = row.createCell((short) rang_cellule); cellLib12.setCellStyle(headerStyle); cellLib12.setCellValue( applicationContext.getMessage("xls.note2", null, Locale.getDefault()).toUpperCase()); rang_cellule++; HSSFCell cellLib13 = row.createCell((short) rang_cellule); cellLib13.setCellStyle(headerStyle); cellLib13.setCellValue( applicationContext.getMessage("xls.result2", null, Locale.getDefault()).toUpperCase()); rang_cellule++; } //info sur les groupes if (!isTraiteEtape) { HSSFCell cellLib14 = row.createCell((short) rang_cellule); cellLib14.setCellStyle(headerStyle); cellLib14.setCellValue( applicationContext.getMessage("xls.groupes", null, Locale.getDefault()).toUpperCase()); rang_cellule++; } int nbrow = 1; for (Inscrit inscrit : listeInscrits) { if (listeCodInd.contains(inscrit.getCod_ind())) { HSSFRow rowInscrit = sheet.createRow((short) nbrow); int rang_cellule_inscrit = 0; HSSFCell cellLibInscrit1 = rowInscrit.createCell((short) rang_cellule_inscrit); cellLibInscrit1.setCellValue(inscrit.getCod_etu()); rang_cellule_inscrit++; HSSFCell cellLibInscrit2 = rowInscrit.createCell((short) rang_cellule_inscrit); cellLibInscrit2.setCellValue(inscrit.getNom()); rang_cellule_inscrit++; HSSFCell cellLibInscrit3 = rowInscrit.createCell((short) rang_cellule_inscrit); cellLibInscrit3.setCellValue(inscrit.getPrenom()); rang_cellule_inscrit++; HSSFCell cellLibInscrit31 = rowInscrit.createCell((short) rang_cellule_inscrit); cellLibInscrit31.setCellValue(inscrit.getDate_nai_ind()); rang_cellule_inscrit++; HSSFCell cellLibInscrit4 = rowInscrit.createCell((short) rang_cellule_inscrit); cellLibInscrit4.setCellValue(inscrit.getEmail()); rang_cellule_inscrit++; if (isTraiteEtape) { HSSFCell cellLibInscrit5 = rowInscrit.createCell((short) rang_cellule_inscrit); cellLibInscrit5.setCellValue(inscrit.getIae()); rang_cellule_inscrit++; } if (!isTraiteEtape) { //if (isEtape) { HSSFCell cellLibInscrit6 = rowInscrit.createCell((short) rang_cellule_inscrit); cellLibInscrit6.setCellValue(inscrit.getCod_etp()); rang_cellule_inscrit++; HSSFCell cellLibInscrit7 = rowInscrit.createCell((short) rang_cellule_inscrit); cellLibInscrit7.setCellValue(inscrit.getCod_vrs_vet()); rang_cellule_inscrit++; HSSFCell cellLibInscrit8 = rowInscrit.createCell((short) rang_cellule_inscrit); cellLibInscrit8.setCellValue(inscrit.getLib_etp()); rang_cellule_inscrit++; //} } if (isSession1) { HSSFCell cellLibInscrit9 = rowInscrit.createCell((short) rang_cellule_inscrit); cellLibInscrit9.setCellValue(inscrit.getNotej()); rang_cellule_inscrit++; HSSFCell cellLibInscrit10 = rowInscrit.createCell((short) rang_cellule_inscrit); cellLibInscrit10.setCellValue(inscrit.getResj()); rang_cellule_inscrit++; } if (isSession2) { HSSFCell cellLibInscrit11 = rowInscrit.createCell((short) rang_cellule_inscrit); cellLibInscrit11.setCellValue(inscrit.getNotes()); rang_cellule_inscrit++; HSSFCell cellLibInscrit12 = rowInscrit.createCell((short) rang_cellule_inscrit); cellLibInscrit12.setCellValue(inscrit.getRess()); rang_cellule_inscrit++; } //ajout info sur les groupes si il y a lieu if (!isTraiteEtape) { HSSFCell cellLibGroupes = rowInscrit.createCell((short) rang_cellule_inscrit); String grpXls = ""; List<String> lcodegroup = Utils.splitStringFromSemiColon(inscrit.getCodes_groupes()); for (String codegroupe : lcodegroup) { if (StringUtils.hasText(grpXls)) { grpXls += ", "; } grpXls += listeGroupes.getItemCaption(codegroupe); } cellLibGroupes.setCellValue(grpXls); rang_cellule_inscrit++; } nbrow++; } } return wb; }
From source file:gatebass.utils.Get_Report_Parent.java
@Override public void setStage(Stage s) { super.setStage(s); thisStage.getScene().setOnKeyReleased((KeyEvent event) -> { switch (event.getCode()) { case ENTER: if (edit.isDisable()) { review.getOnAction().handle(null); } else { edit.getOnAction().handle(null); }/*from w w w. j ava 2 s . c om*/ break; } }); review.disableProperty().bind(tableView.getSelectionModel().selectedItemProperty().isNull()); if (!edit.isDisabled()) { edit.disableProperty().bind(review.disableProperty()); } download_file.disableProperty().bind(review.disableProperty()); edit.init("pencil", 15); review.init("eye", 15); download_file.init("download", 15); export_to_excel.init("export", 15); download_file.setOnAction((ActionEvent event) -> { // Printer printer = Printer.getDefaultPrinter(); // PageLayout pageLayout = printer.createPageLayout(Paper.A4, PageOrientation.PORTRAIT, Printer.MarginType.EQUAL); // // double scaleX = pageLayout.getPrintableWidth() / tableView.getBoundsInParent().getWidth(); // double scaleY = pageLayout.getPrintableHeight() / tableView.getBoundsInParent().getHeight(); // tableView.getTransforms().add(new Scale(scaleX, scaleY)); // // PrinterJob printerJob = PrinterJob.createPrinterJob(); // if (printerJob.showPrintDialog(s) && printerJob.printPage(pageLayout, tableView)) { // printerJob.endJob(); // System.out.println("printed"); // } // FileChooser fileChooser = new FileChooser(); // File file = fileChooser.showSaveDialog(thisStage); // if (file == null) { // return; // } // try { // file.mkdirs(); // List<IndividualFile> files_list = databaseHelper.individualFileDao.getAll("individual_id", databaseHelper.individualsDao.queryForId(tableView.getSelectionModel().getSelectedItem().getId())); // for (IndividualFile f : files_list) { // FileUtils.copyFileToDirectory(new File(f.getAddress()), file); // } // } catch (IOException ex) { // Logger.getLogger(Fxml_Get_Report_Individual_List.class.getName()).log(Level.SEVERE, null, ex); // } }); export_to_excel.setOnAction((ActionEvent event) -> { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle(" "); fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Excel(*.xls)", "*.xls")); File file = fileChooser.showSaveDialog(thisStage); if (file == null) { return; } try { FileOutputStream fileOut = new FileOutputStream(file); HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet worksheet = workbook.createSheet(""); int cellCount = 1; HSSFRow row = worksheet.createRow(0); row.createCell(0).setCellValue("?"); for (TableColumn tc : tableView.getColumns()) { if (tc.isVisible()) { HSSFCell cell = row.createCell(cellCount); cell.setCellValue(tc.getText() + ""); cellCount++; } } int rowCount = 1; for (T lf : tableView.getItems()) { row = worksheet.createRow(rowCount); cellCount = 1; row.createCell(0).setCellValue(rowCount + ""); for (TableColumn tc : tableView.getColumns()) { if (tc.isVisible()) { HSSFCell cell = row.createCell(cellCount); try { cell.setCellValue(tc.getCellObservableValue(rowCount - 1).getValue() + ""); } catch (Exception e) { } cellCount++; } } rowCount++; } workbook.write(fileOut); fileOut.flush(); fileOut.close(); } catch (Exception e) { e.printStackTrace(); } }); userName.setText(" : " + users.getName_fa()); sum.textProperty().bind(Bindings.size(tableView.itemsProperty().get()).asString()); tableView.setFixedCellSize(35d); textField.textProperty() .addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) -> { tableFiltered(textFiltered(newValue)); }); tableView.addEventHandler(ColumnFilterEvent.FILTER_CHANGED_EVENT, (ColumnFilterEvent event) -> { tableFiltered(textFiltered(textField.getText())); }); tableView.getSelectionModel().selectedItemProperty() .addListener((ObservableValue<? extends T> observable, T oldValue, T newValue) -> { if (newValue != null) { under_table_update(newValue.getId()); } else { replica_Table.getItems().clear(); work_table.getItems().clear(); warning_Table.getItems().clear(); } }); tableView.setRowFactory((TableView<T> param) -> { TableRow<T> row = new TableRow<>(); row.setOnMouseClicked((MouseEvent event) -> { if (row.getIndex() == tableView.getSelectionModel().getSelectedIndex() && event.getClickCount() >= 2) { if (edit.isDisable()) { review.getOnAction().handle(null); } else { edit.getOnAction().handle(null); } } }); return row; }); }
From source file:gda.hrpd.data.ExcelWorkbook.java
License:Open Source License
/** * modify if exist, or create if not exist, a cell in the specified row at specified position with the specified * value.//from w w w .j a v a2 s .c o m * * @param row * @param column * @param value * @throws IOException */ public void setCellValue(HSSFRow row, int column, String value) throws IOException { HSSFCell cell = row.getCell(column); if (cell == null) // add more cell to the row if (!writeable) { logger.error("Cannot create a new cell in file {}.", this.filename); throw new IOException("Cannot write to file {}." + this.filename); } cell = row.createCell((short) column); cell.setCellValue(new HSSFRichTextString(value)); }
From source file:gda.hrpd.data.ExcelWorkbook.java
License:Open Source License
/** * modify if exist, or create if not exist, a cell in the specified row at specified position with the specified * value.//w w w . j av a 2 s. co m * * @param row * @param column * @param value * @throws IOException */ public void setCellValue(HSSFRow row, int column, double value) throws IOException { HSSFCell cell = row.getCell(column); if (cell == null) if (!writeable) { logger.error("Cannot create a new sheet in file {}.", this.filename); throw new IOException("Cannot write to file {}." + this.filename); } // add more cell to the row cell = row.createCell((short) column); cell.setCellValue(value); }
From source file:gda.hrpd.data.ExcelWorkbook.java
License:Open Source License
/** * modify if exist, or create if not exist, a cell in the specified row at specified position with the specified * value./* w w w. ja va 2 s . c o m*/ * * @param row * @param column * @param value * @throws IOException */ public void setCellValue(HSSFRow row, int column, boolean value) throws IOException { HSSFCell cell = row.getCell(column); if (cell == null) if (!writeable) { logger.error("Cannot create a new sheet in file {}.", this.filename); throw new IOException("Cannot write to file {}." + this.filename); } // add more cell to the row cell = row.createCell((short) column); cell.setCellValue(value); }