473,396 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Formatting excel sheets

mehj123
55
HI,

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
  1.  
  2. <%@ page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
  3. <%@ page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
  4. <%@ page import="org.apache.poi.hssf.usermodel.HSSFCell"%>
  5. <%@ page import="org.apache.poi.hssf.usermodel.HSSFRow"%>
  6. <%@ page import="org.apache.poi.hssf.usermodel.HSSFFont"%>
  7. <%@ page import="org.apache.poi.hssf.usermodel.HSSFCellStyle"%>
  8. <%@ page import="org.apache.poi.hssf.usermodel.HSSFPrintSetup"%>
  9. <%@ page import="java.io.*" %>
  10. <%@ page import="java.sql.*,com.*" %>
  11. <%//response.setContentType("application/vnd.ms-excel");
  12. //response.setHeader("Content-Disposition","attachment;filename=CreateCell1.xls");%>
  13. <%try
  14. {
  15. DataRetriver dr=new DataRetriver();
  16. ResultSet rs=dr.fetch();
  17. ResultSet rs1=null;
  18. String company_name="";
  19. HSSFWorkbook wb = new HSSFWorkbook();
  20. HSSFSheet sheet = wb.createSheet("new sheet");
  21. HSSFRow row;
  22. int i=0,j=0;
  23. if(rs != null)
  24. {
  25. while(rs.next())
  26. {
  27. company_name = rs.getString(1);
  28. row = sheet.createRow((short)i);
  29. HSSFCell cell = row.createCell((short)3);
  30. cell.setCellValue(company_name);
  31. HSSFFont font = wb.createFont();
  32. font.setFontHeightInPoints((short)16);
  33. font.setFontName("Comic Sans");
  34. font.setItalic(true);
  35. HSSFCellStyle cellStyle = wb.createCellStyle();
  36. cellStyle.setFont(font);
  37. cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
  38. cell.setCellStyle(cellStyle);
  39. try
  40. {
  41.     j=i+1;
  42.     DataRetriver dr1=new DataRetriver();
  43.     rs1=dr1.fetch1(company_name);
  44.     if(rs1!=null)
  45.     {
  46.      while(rs1.next())
  47.      {
  48.      row = sheet.createRow((short)j);
  49.      HSSFCell cell2 = row.createCell((short)0);
  50.      String name = rs1.getString(1)+" "+rs1.getString(2);
  51.      cell2.setCellValue(name);
  52.      HSSFCell cell3 = row.createCell((short)1);
  53.      cell3.setCellValue(rs1.getInt(3));
  54.      HSSFCell cell4 = row.createCell((short)2);
  55.      cell4.setCellValue(rs1.getString(5));
  56.      HSSFCell cell5 = row.createCell((short)3);
  57.      cell5.setCellValue(rs1.getString(6));
  58.      HSSFCell cell6 = row.createCell((short)4);
  59.      cell6.setCellValue(rs1.getString(7));
  60.      HSSFCell cell7 = row.createCell((short)5);
  61.      cell7.setCellValue(rs1.getString(8));
  62.      i=j;
  63.      j++;
  64.      }
  65.     }
  66. }
  67. catch(Exception e)
  68. {
  69.     out.println("Exception occured "+e);
  70. }
  71. i++;
  72. row = sheet.createRow((short)i+1);
  73. i++;
  74.  
  75. }
  76.  
  77. }
  78.  
  79. FileOutputStream fileOut = new FileOutputStream("C:\\Excel\\createCell.xls");
  80. wb.write(fileOut);
  81. fileOut.close();
  82. }
  83. catch(Exception e)
  84. {
  85. out.println("Exception occured in main" +e);
  86. }%>
  87.  
Can anyone help?? Thanks in advance
Oct 23 '07 #1
1 3962
acoder
16,027 Expert Mod 8TB
JSP and JavaScript are not the same language.

I am moving this to the Java forum where you are more likely to get help with your problem.
Oct 23 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Ilan | last post by:
Hi all I need to add data from two Excel sheets (both on the same workbook) to an existing table in my SQL DB. The problem is that each sheet holds different fields for the same record, though...
1
by: javzxp | last post by:
Hi I'd like to use C# to open an existing Excel workbook and save each worksheet it contains into a new Excel file. The name of each new Excel file should be the name of the worksheet copied...
8
by: Sam | last post by:
Hi All, I posted this message few days ago. No one has answered so far. I just would like to know if it is possible to do or not. Even if you can not tell me how to do this, maybe you know which...
1
by: Esmail Bonakarian | last post by:
Greetings all, What is the best way to access specific records in an Excel file? I have an Excel file, I want to randomly and repeatedly (maybe around up to 50 times) draw some rows of data...
0
by: ammu001 | last post by:
Response.ContentType Excel I am trying to export a datagrid into an excel sheet. What it now does is the entire page is saved as an excel sheet in XlHtml file format. I want it in...
4
by: =?Utf-8?B?QnJpYW5ESA==?= | last post by:
Hi Does anyone know of a way (via code behind) to pull a single sheet out of a Excel workbook and convert it to a stand alone html document? Thanks Brian
3
by: Chris | last post by:
I have a python script that is driving Excel and using the win32com module. However, upon program completion there's still an Excel.exe process running in the background that I must terminate...
1
by: afr0ninja | last post by:
Hello! I'm having an issue with the OutputTo function of Access. I have a few queries that I export to excel (by way of the OutputTo function) This works fine. I then take an excel sheet...
1
by: DennisBetten | last post by:
First of all, I need to give some credit to Mahesh Chand for providing me with an excellent basis to export data to excel. What does this code do: As the title says, this code is capable of...
10
by: afromanam | last post by:
Regards, Please help What I'm trying to do is this: (and I can't use reports since I must export to Excel) I export some queries to different tabs in an excel workbook I then loop through...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.