You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Wadi Jalil Maluf <wa...@yahoo.com.ar> on 2009/03/31 16:21:56 UTC
How To Download Excel File?
Hi All, I would like to know how can I put a link into a page so when the
user clicks I fetch some data from database , export it to Excel so the user
directly downloads an xls file with the content.
Any help is appreciated,
Thanks in advance,
Wadi
Re: How To Download Excel File?
Posted by UPBrandon <bc...@up.com>.
Check out my responses in this discussion...
http://www.nabble.com/Opening-DynamicWebResource-from-Button-AjaxButton--td15459841.html#a21462901
I had some trouble getting generated files to download right at first. They
either caused Wicket to become non-responsive or I couldn't provide a file
name or MIME type. The solution I eventually came up with works very well.
-Brandon
wadi wrote:
>
> Hi All, I would like to know how can I put a link into a page so when the
> user clicks I fetch some data from database , export it to Excel so the
> user
> directly downloads an xls file with the content.
>
> Any help is appreciated,
>
> Thanks in advance,
>
> Wadi
>
>
>
--
View this message in context: http://www.nabble.com/How-To-Download-Excel-File--tp22806518p22808994.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: How To Download Excel File?
Posted by Jim Pinkham <pi...@gmail.com>.
Another way I'm using is like this (it works best if your clients have excel
installed of course)
Markup: http://pastebin.com/m41ee5cbe
Java: http://pastebin.com/m488291d4
With the most important bits being:
@Override
protected void configureResponse() {
super.configureResponse();
getRequestCycle().getResponse().setContentType("application/x-msexcel");
}
and then a simple DataView with something like this:
...
<head>
<title>Excel Download</title>
<meta http-equiv="Content-Type" content="application/x-msexcel">
<meta http-equiv="Content-disposition": attachment;
filename="whatever_default_filename.xls">
</head>
<body>
<table>
<tr>
<th>Name</th>
... more ...
</tr>
<tr wicket:id="rows">
<td wicket:id="name"> </td>
That makes most browsers open a dialog box where the user can open (usually
in excel) or save the html - no binary conversion to excel's file format is
really needed - excel can read HTML just fine. So if you are just doing a
simple tabular report like I'm doing here, this could be a good option for
you.
-- Jim Pinkham
On Tue, Mar 31, 2009 at 12:58 PM, Luther Baker <lu...@gmail.com>wrote:
> These responses were great! I learned something from almost each variant of
> the answer.
>
> For what its worth, depending on how the app will be used - one might need
> to be careful about writing files to the filesystem ... but again, thanks
> for all the great examples listed here.
>
> -Luther
>
>
>
> On Tue, Mar 31, 2009 at 10:11 AM, francisco treacy <
> francisco.treacy@gmail.com> wrote:
>
> > hola wadi
> >
> > to generate the excel file, have a look at the poi apache project:
> > http://poi.apache.org/spreadsheet/index.html
> >
> > then you will need to create a resource for that file / byte array.
> > you might find some inspiration from this pastie:
> > http://paste.pocoo.org/show/110449/
> >
> > finally, use
> >
> > new ResourceLink<Void>("downloadAsExcel", new PdfResource() {
> >
> > (...)
> >
> > }
> >
> > declare the link on your html and you're done!
> >
> > francisco
> >
> >
> > 2009/3/31 Wadi Jalil Maluf <wa...@yahoo.com.ar>:
> > > Hi All, I would like to know how can I put a link into a page so when
> the
> > > user clicks I fetch some data from database , export it to Excel so the
> > user
> > > directly downloads an xls file with the content.
> > >
> > > Any help is appreciated,
> > >
> > > Thanks in advance,
> > >
> > > Wadi
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>
Re: How To Download Excel File?
Posted by Luther Baker <lu...@gmail.com>.
These responses were great! I learned something from almost each variant of
the answer.
For what its worth, depending on how the app will be used - one might need
to be careful about writing files to the filesystem ... but again, thanks
for all the great examples listed here.
-Luther
On Tue, Mar 31, 2009 at 10:11 AM, francisco treacy <
francisco.treacy@gmail.com> wrote:
> hola wadi
>
> to generate the excel file, have a look at the poi apache project:
> http://poi.apache.org/spreadsheet/index.html
>
> then you will need to create a resource for that file / byte array.
> you might find some inspiration from this pastie:
> http://paste.pocoo.org/show/110449/
>
> finally, use
>
> new ResourceLink<Void>("downloadAsExcel", new PdfResource() {
>
> (...)
>
> }
>
> declare the link on your html and you're done!
>
> francisco
>
>
> 2009/3/31 Wadi Jalil Maluf <wa...@yahoo.com.ar>:
> > Hi All, I would like to know how can I put a link into a page so when the
> > user clicks I fetch some data from database , export it to Excel so the
> user
> > directly downloads an xls file with the content.
> >
> > Any help is appreciated,
> >
> > Thanks in advance,
> >
> > Wadi
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: How To Download Excel File?
Posted by francisco treacy <fr...@gmail.com>.
hola wadi
to generate the excel file, have a look at the poi apache project:
http://poi.apache.org/spreadsheet/index.html
then you will need to create a resource for that file / byte array.
you might find some inspiration from this pastie:
http://paste.pocoo.org/show/110449/
finally, use
new ResourceLink<Void>("downloadAsExcel", new PdfResource() {
(...)
}
declare the link on your html and you're done!
francisco
2009/3/31 Wadi Jalil Maluf <wa...@yahoo.com.ar>:
> Hi All, I would like to know how can I put a link into a page so when the
> user clicks I fetch some data from database , export it to Excel so the user
> directly downloads an xls file with the content.
>
> Any help is appreciated,
>
> Thanks in advance,
>
> Wadi
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: How To Download Excel File?
Posted by Michael O'Cleirigh <mi...@rivulet.ca>.
Hi Wadi,
The easy way is to have the conversion to xls occur within the link
action (extracting from db and storing to a temporary file in XLS format).
then you can use a DownloadLink with the model set to the File
(generatedXLSFileName).
If it is not tied to some other process you will have to create a
resource that knows how to do the conversion. Have a look at extending
DynamicWebResource.
Regards,
Mike
> Hi All, I would like to know how can I put a link into a page so when the
> user clicks I fetch some data from database , export it to Excel so the user
> directly downloads an xls file with the content.
>
> Any help is appreciated,
>
> Thanks in advance,
>
> Wadi
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: How To Download Excel File?
Posted by Thies Edeling <th...@rrm.net>.
>> I could be wrong - but maybe the question is about how best to structure
>> this in Wicket ..
>>
>
> it's just that easy (this is Scala, not Java):
>
> add( new Link( ImageLink.ID_LINK ) {
> def onClick = {
> val resourceStream = new ByteArrayResourceStream(
> xlsExporter.createExcel, "application/vnd.ms-excel" );
> getRequestCycle.setRequestTarget( new ResourceStreamRequestTarget(
> resourceStream ) {
> override def getFileName = "export.xls"
> } )
> }
> })
>
> ByteArrayResourceStream is a simple implementation of IResourceStream. Creating
> the Excel bytearray is another issue (I suggest using Apache POI).
>
or extend DynamicWebResource and return your own ResourceState with the
excel file as a byte array returned by getData and use
application/x-ms-excel as the content type. To link to the excel, mount
the resource in your WebApplication, check the javadoc of
ResourceReference on how to do so.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: How To Download Excel File?
Posted by Jan Kriesten <kr...@mail.footprint.de>.
Hi,
> I could be wrong - but maybe the question is about how best to structure
> this in Wicket ..
it's just that easy (this is Scala, not Java):
add( new Link( ImageLink.ID_LINK ) {
def onClick = {
val resourceStream = new ByteArrayResourceStream(
xlsExporter.createExcel, "application/vnd.ms-excel" );
getRequestCycle.setRequestTarget( new ResourceStreamRequestTarget(
resourceStream ) {
override def getFileName = "export.xls"
} )
}
})
ByteArrayResourceStream is a simple implementation of IResourceStream. Creating
the Excel bytearray is another issue (I suggest using Apache POI).
Best regards, --- Jan.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: How To Download Excel File?
Posted by Luther Baker <lu...@gmail.com>.
I could be wrong - but maybe the question is about how best to structure
this in Wicket ..
Should it be a bookmarkable link? Should it be an action link? If I do the
work in my Action style link, how does one directly return content from an
action link as opposed to setting page response, etc.
-Luther
On Tue, Mar 31, 2009 at 9:30 AM, Linda van der Pal <
lvdpal@heritageagenturen.nl> wrote:
> Not related to Wicket, but this might be a start:
> http://api.openoffice.org/
>
> Regards,
> Linda
>
> Wadi Jalil Maluf wrote:
>
>> Hi All, I would like to know how can I put a link into a page so when the
>> user clicks I fetch some data from database , export it to Excel so the
>> user
>> directly downloads an xls file with the content.
>>
>> Any help is appreciated,
>>
>> Thanks in advance,
>>
>> Wadi
>>
>>
>> ------------------------------------------------------------------------
>>
>>
>> No virus found in this incoming message.
>> Checked by AVG - www.avg.com Version: 8.5.285 / Virus Database:
>> 270.11.34/2032 - Release Date: 03/31/09 06:02:00
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: How To Download Excel File?
Posted by Linda van der Pal <lv...@heritageagenturen.nl>.
Not related to Wicket, but this might be a start: http://api.openoffice.org/
Regards,
Linda
Wadi Jalil Maluf wrote:
> Hi All, I would like to know how can I put a link into a page so when the
> user clicks I fetch some data from database , export it to Excel so the user
> directly downloads an xls file with the content.
>
> Any help is appreciated,
>
> Thanks in advance,
>
> Wadi
>
>
>
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 8.5.285 / Virus Database: 270.11.34/2032 - Release Date: 03/31/09 06:02:00
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org