I am writing a code in jsp to retrieve the details from a database and saving it as excel sheet. I am first retrieving the company name and then according to the company, I am grouping the employees.
I am getting the excel sheet with all the details but I cant find a way to put some separators between the details of the two companies.This is my code
Expand|Select|Wrap|Line Numbers
- <%@ page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
- <%@ page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
- <%@ page import="org.apache.poi.hssf.usermodel.HSSFCell"%>
- <%@ page import="org.apache.poi.hssf.usermodel.HSSFRow"%>
- <%@ page import="org.apache.poi.hssf.usermodel.HSSFFont"%>
- <%@ page import="org.apache.poi.hssf.usermodel.HSSFCellStyle"%>
- <%@ page import="org.apache.poi.hssf.usermodel.HSSFPrintSetup"%>
- <%@ page import="java.io.*" %>
- <%@ page import="java.sql.*,com.*" %>
- <%//response.setContentType("application/vnd.ms-excel");
- //response.setHeader("Content-Disposition","attachment;filename=CreateCell1.xls");%>
- <%try
- {
- DataRetriver dr=new DataRetriver();
- ResultSet rs=dr.fetch();
- ResultSet rs1=null;
- String company_name="";
- HSSFWorkbook wb = new HSSFWorkbook();
- HSSFSheet sheet = wb.createSheet("new sheet");
- HSSFRow row;
- int i=0,j=0;
- if(rs != null)
- {
- while(rs.next())
- {
- company_name = rs.getString(1);
- row = sheet.createRow((short)i);
- HSSFCell cell = row.createCell((short)3);
- cell.setCellValue(company_name);
- HSSFFont font = wb.createFont();
- font.setFontHeightInPoints((short)16);
- font.setFontName("Comic Sans");
- font.setItalic(true);
- HSSFCellStyle cellStyle = wb.createCellStyle();
- cellStyle.setFont(font);
- cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
- cell.setCellStyle(cellStyle);
- try
- {
- j=i+1;
- DataRetriver dr1=new DataRetriver();
- rs1=dr1.fetch1(company_name);
- if(rs1!=null)
- {
- while(rs1.next())
- {
- row = sheet.createRow((short)j);
- HSSFCell cell2 = row.createCell((short)0);
- String name = rs1.getString(1)+" "+rs1.getString(2);
- cell2.setCellValue(name);
- HSSFCell cell3 = row.createCell((short)1);
- cell3.setCellValue(rs1.getInt(3));
- HSSFCell cell4 = row.createCell((short)2);
- cell4.setCellValue(rs1.getString(5));
- HSSFCell cell5 = row.createCell((short)3);
- cell5.setCellValue(rs1.getString(6));
- HSSFCell cell6 = row.createCell((short)4);
- cell6.setCellValue(rs1.getString(7));
- HSSFCell cell7 = row.createCell((short)5);
- cell7.setCellValue(rs1.getString(8));
- i=j;
- j++;
- }
- }
- }
- catch(Exception e)
- {
- out.println("Exception occured "+e);
- }
- i++;
- row = sheet.createRow((short)i+1);
- i++;
- }
- }
- FileOutputStream fileOut = new FileOutputStream("C:\\Excel\\createCell.xls");
- wb.write(fileOut);
- fileOut.close();
- }
- catch(Exception e)
- {
- out.println("Exception occured in main" +e);
- }%>