I am having reports generated in jsp with HTML codings in tabular format. On report displayed page I have to use one button , which on click has to export to excel sheet.
I tried using below code.
String mimeType = "applicatio n/vnd.ms-excel";
response.setCon tentType(mimeTy pe);
response.setHea der("content-disposition","a ttachment; filename=totalp urgeexcel.xls") ;
But the problem I am facing is , in the report page, header and footer are also their. So while exporting header and footer are also saved in excel.
Another problem is I have a main page where link to particular report is displayed. When I click on one report link itself its showing me popup for saving, its not displaying the report generated page, all datas in that are saving in excel.
Please help me with suitable solution.
1 18343 Dököll 2,364
Recognized Expert Top Contributor
Greetins!
You can try something like this, pretty generic code but you will need Apache's API called POI to b able to relate to Microsoft's file types, a few simple jar files. You will also need Tomcat Server for this to work. Add the jar files in Tomcat lib directory: -
....Call this jsp file whatever ou want for starters
-
-
<%@ page language="java" import="java.io.*" %>
-
-
...Begin your form post to AddToExcel.jsp page
-
...A simple textfield t record the actuall excel file name
-
-
<form method="post" action="AddToExcel.jsp">
-
<p><font color="#800000" size="5">Enter File Name Here:</font>
-
<input type="text" name="excel_sheet_name" size="20"></p>
-
<p><input type="submit" value="Submit"
-
onclick="document.location='AddToExcel.jsp';"/>
-
</p>
-
-
</form>
-
-
Here is your AddToExcel.jsp: -
-
...import necessary libraries
-
<%@ 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"%>
-
-
...import io, tells system to recieve a file
-
-
<%@ page import="java.io.*" %>
-
-
...grab te excel file name
-
-
<%String name=request.getParameter("excel_sheet_name");%>
-
-
...create a workbook, a couple of cells, name yoursheet<%try{
-
-
HSSFWorkbook wb = new HSSFWorkbook();
-
HSSFSheet sheet = wb.createSheet("MyFirstExcelSheet");
-
HSSFRow row = sheet.createRow((short)0);
-
HSSFCell cell = row.createCell((short)0);
-
-
...add values to your cells, notice you are adding to 4 cells here
-
-
cell.setCellValue(1);
-
row.createCell((short)1).setCellValue("AddSomeTextHere");
-
row.createCell((short)2).setCellValue("AddSomeTextHere");
-
row.createCell((short)3).setCellValue("AddSomeTextHere");
-
FileOutputStream fileOut = new FileOutputStream("C:\\"+name+".xls");
-
-
wb.write(fileOut);
-
fileOut.close();
-
}catch ( Exception ex ){
-
}
-
-
%>
-
-
Excel File added...
-
and there you have it... Hope this gives you a idea. You can then grab data from say an Access database and load to excel ta way, as needed:-)
Happy coding!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Jason |
last post by:
Can anyone point me to some sample code or tutorial that shows how I can
export data from a database to an Excel spreadsheet that is already created
on the server?
I have an Excel spreadsheet that contains a number of labeled cells and
sheets. When someone clicks the "Export to Excel" button on my asp page, I
want to export the required data from my sql database to the Excel
spreadsheet (putting the data in the appropriate cells and...
|
by: Robin Cushman |
last post by:
Hi all,
I need some help -- I'm working with an A2K database, using DAO, and
am trying to read records into a Crystal Report and then export it to
a folder on our network as an Excel spreadsheet. I'm having trouble
with my code at the point at which it hits ".ReadRecords" -- the
module just runs and runs without generating anything. I've gotten
this code to correctly save .rpt files without any data, but not with
data, nor have I been...
|
by: David |
last post by:
(dhl)Using 2K. I have a query I want to export to excel. There are
35,000+ lines for this query. I created a macro to run on a schedule
to export the excel file to a network shared drive. I can manual
export the query to excel, but when I run the macro, access said
"There are too many rows to output, based on limitation specified by
the output Format". In the macro I am using the "Output To" "Query"
to "Excel". I do not see where I...
|
by: DC Gringo |
last post by:
I have a simple button that should open another window and export a datagrid
to an Excel file. I'm getting: "Name 'window' is not declared."
What do I need to declare or import?
<INPUT ID="Button5" ONCLICK="Button5_Click" NAME="Button5" TYPE="button"
VALUE="Export to Excel">
Sub Button5_Click()
|
by: kieran |
last post by:
Hi,
I have an 'export to excel' button on my Datagrid. All works well
except that on my Datagrid, I have sub total rows. The subtotal rows
use colspan so that the subtotals are given above certain columns
When I export to excel, I do not have the colspan. As a result, the
subtotals appear over the wrong columns in Excel.
| |
by: Hemant Sipahimalani |
last post by:
The following piece of code is being used to export HTML to excel.
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
HttpContext.Current.Response.AddHeader("content-disposition",
"attachment;filename=ABC.xls")
HttpContext.Current.Response.Write(strHTML)
HttpContext.Current.Response.End()
However when the user tries to save it the Default File Type is Web
Page(*.htm; *.html)
|
by: JawzX01 |
last post by:
Hello All,
First, thank you for any help you can provide.
I'm trying to do a simple export to excel. I've used the classic
code that is all over the internet, and of course it worked without a
problem.
The problem is that I want to add text above the data grid in the
excel sheet. The text already exists on the web page in various panels
(there is different text depending on the parameters of the datagrid
|
by: Mike |
last post by:
On my page I'm using an updatepanel, updateProgress, and a ModalProgress,
everything works great But when I try to export my GridView to excel I'm
getting the following error message:
Sys.WebForms.PageRequestManagerParserErrorException: The message received
from the server could not be parsed. Common cause for this error are when
the response is modified by calls to Response.Write(), response filters,
HttpModules, or server trace is...
|
by: mustaqueahmad |
last post by:
Hi All,
I am getting export to excel problem when I am giving IPAddress in URL, but it is working correct when am giving localhost and page name.
eg : when I am writing My machine IP address and aspx pagename like 192.xxx.xxx.xx/exporttoexcell.aspx then popup page is not working. the popup page is being closed automatically , and export to excel option is not comming.
for some reason when it opens within a scripted popup (js:...
|
by: Tennotrumps |
last post by:
I am trying to export a report to excel but the "excel" option is greyed out. I can export the query the report is based on, but not the report.
However, if I open the database on another PC I CAN export to excel.
I've tried reinstalling Access, but it doesn't make any difference.
I've also installed the compatability file (as the version of excel is 2003), but to no avail.
What am I missing?
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |