You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by dv...@newfoundmarket.com on 2008/04/01 09:31:44 UTC

export excel file via an OutputStream

Hello:
I am trying to export dynamically generated excel file.
The generator would send the file.xls to an OutputStream.

In wicket, I am trying to use example as below but
 how can I connect the OutputStream to the inputstream
ins.  Pipedoutputstream would block. Using a separate thread
is not desirable.

public void onClick() {
 
  IResourceStream stream = new AbstractResourceStream() {

                        public InputStream getInputStream() throws ResourceStreamNotFoundException {
                         
                            
                            return ins;
                        }

                        public void close() throws IOException {
                            ins.close();
                        }
                    };
                    
                    getRequestCycle().setRequestTarget(
                            new ResourceStreamRequestTarget(stream).setFileName("file.xls"));

Re: export excel file via an OutputStream

Posted by Igor Vaynberg <ig...@gmail.com>.
it is trivial to implement and can be pretty much factored out of downloadlink.

-igor


On Tue, Apr 1, 2008 at 11:35 PM, Erik van Oosten <e....@grons.nl> wrote:
> That looks like an excellent API. Would it be very hard to implement this?
>
>  Personally I am also looking for something like this, but then
>  bookmarkable. I got some suggestions on how to do this with the current
>  APIs, but I did not like them at all. So now I am using a servlet.
>
>  Regards,
>     Erik.
>
>
>
>  Al Maw wrote:
>  > I think he makes a valid point, personally. People do want to do this sort
>  > of thing quite frequently. It wouldn't kill us to implement an
>  > OutputStreamLink that looked like this:
>  >
>  > add(new StreamingLink("link") {
>  >     public String getFileName() {
>  >         return "download.xls";
>  >     }
>  >     public String getMimeType() {
>  >         return "application/vnd.excel"; // Or whatever it is.
>  >     }
>  >     public void writeToOutputStream(OutputStream outputStream) {
>  >         excelGenerator.writeOutput(outputStream);
>  >     }
>  > });
>  >
>  > I don't think the current API here is very pleasant or obvious to use.
>  >
>  > Regards,
>  >
>  > Al
>  >
>  >
>
>
>  --
>  Erik van Oosten
>  http://www.day-to-day-stuff.blogspot.com/
>
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>  For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: export excel file via an OutputStream

Posted by Erik van Oosten <e....@grons.nl>.
That looks like an excellent API. Would it be very hard to implement this?

Personally I am also looking for something like this, but then 
bookmarkable. I got some suggestions on how to do this with the current 
APIs, but I did not like them at all. So now I am using a servlet.

Regards,
    Erik.


Al Maw wrote:
> I think he makes a valid point, personally. People do want to do this sort
> of thing quite frequently. It wouldn't kill us to implement an
> OutputStreamLink that looked like this:
>
> add(new StreamingLink("link") {
>     public String getFileName() {
>         return "download.xls";
>     }
>     public String getMimeType() {
>         return "application/vnd.excel"; // Or whatever it is.
>     }
>     public void writeToOutputStream(OutputStream outputStream) {
>         excelGenerator.writeOutput(outputStream);
>     }
> });
>
> I don't think the current API here is very pleasant or obvious to use.
>
> Regards,
>
> Al
>
>   


--
Erik van Oosten
http://www.day-to-day-stuff.blogspot.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: export excel file via an OutputStream

Posted by Al Maw <wi...@almaw.com>.
I think he makes a valid point, personally. People do want to do this sort
of thing quite frequently. It wouldn't kill us to implement an
OutputStreamLink that looked like this:

add(new StreamingLink("link") {
    public String getFileName() {
        return "download.xls";
    }
    public String getMimeType() {
        return "application/vnd.excel"; // Or whatever it is.
    }
    public void writeToOutputStream(OutputStream outputStream) {
        excelGenerator.writeOutput(outputStream);
    }
});

I don't think the current API here is very pleasant or obvious to use.

Regards,

Al

On Tue, Apr 1, 2008 at 1:15 PM, Peter Ertl <pe...@gmx.net> wrote:

> use AbstractResourceStreamWriter
>
>  > Wicket got to have a more structured api for this common task.
> usually it's not wicket but you when something is not working the way
> you expect it
>
>
>
>
>
> Am 01.04.2008 um 09:31 schrieb dvd@newfoundmarket.com:
>
> > Hello:
> > I am trying to export dynamically generated excel file.
> > The generator would send the file.xls to an OutputStream.
> >
> > In wicket, I am trying to use example as below but
> >  how can I connect the OutputStream to the inputstream
> > ins.  Pipedoutputstream would block. Using a separate thread
> > is not desirable.
> >
> > public void onClick() {
> >
> >   IResourceStream stream = new AbstractResourceStream() {
> >
> >                         public InputStream getInputStream() throws
> > ResourceStreamNotFoundException {
> >
> >
> >                             return ins;
> >                         }
> >
> >                         public void close() throws IOException {
> >                             ins.close();
> >                         }
> >                     };
> >
> >                     getRequestCycle().setRequestTarget(
> >                             new
> > ResourceStreamRequestTarget(stream).setFileName("file.xls"));
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: export excel file via an OutputStream

Posted by Peter Ertl <pe...@gmx.net>.
use AbstractResourceStreamWriter

 > Wicket got to have a more structured api for this common task.
usually it's not wicket but you when something is not working the way  
you expect it





Am 01.04.2008 um 09:31 schrieb dvd@newfoundmarket.com:

> Hello:
> I am trying to export dynamically generated excel file.
> The generator would send the file.xls to an OutputStream.
>
> In wicket, I am trying to use example as below but
>  how can I connect the OutputStream to the inputstream
> ins.  Pipedoutputstream would block. Using a separate thread
> is not desirable.
>
> public void onClick() {
>
>   IResourceStream stream = new AbstractResourceStream() {
>
>                         public InputStream getInputStream() throws  
> ResourceStreamNotFoundException {
>
>
>                             return ins;
>                         }
>
>                         public void close() throws IOException {
>                             ins.close();
>                         }
>                     };
>
>                     getRequestCycle().setRequestTarget(
>                             new  
> ResourceStreamRequestTarget(stream).setFileName("file.xls"));


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Export Excel file containing string and rendered component

Posted by rainIsWet <or...@hotmail.de>.
If You try to use Frank Silbermanns suggestion this should be the normal
behavior because it breaks the RequestCycle...

Use Johan Compagners solution with something like a ByteArrayOutputstream as
the stream-source of "public void write(Response output)". Worked fine for
me.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/export-excel-file-via-an-OutputStream-tp1883922p4260504.html
Sent from the Users forum 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: Export Excel file containing string and rendered component

Posted by Altuğ Bilgin Altıntaş <al...@gmail.com>.
Hi;

After using  WebResponse to export excel then clicking a Link gives *Page
expired* error.

Any suggestion ?


2009/6/4 Igor Vaynberg <ig...@gmail.com>

> you have the webresponse, can you not simply write into it?
>
> -igor
>
> On Thu, Jun 4, 2009 at 9:49 AM, Frank Silbermann
> <fr...@fedex.com> wrote:
> >
> > I, too, am trying to have my application download MS Excel files.  Until
> now,
> > mine have contained the content of a DataTable, using the code I received
> > from the mailing list three years ago:
> >
> > Button button = new Button("excelExport") {
> >    public void onSubmit() {
> >        getRequestCycle().setRequestTarget(
> >                        new ComponentRequestTarget(dataTable)
> >        );
> >        WebResponse wr = (WebResponse)getResponse();
> >        wr.setContentType( "excel/ms-excel; name="+getMSExcelFilename() );
> >        wr.setHeader( "content-disposition",
> > "attachment;filename="+getMSExcelFilename() );
> >    }
> > };
> >
> > The file downloaded contains an HTML fragment that both MS Excel and MS
> Word
> > can interpret, if one opens the resulting file in those applications.
> >
> > Now my users told me they would like the download to contain not just the
> > data, but the date of its creation.  Is there an easy way to pre-pend an
> > arbitrary string to that HTML fragment?  I don't really understand the
> > details of Wicket's page rendering process, and looking at the classes
> I've
> > been using there don't seem to be any obvious hooks.
> >
> >
> >
> >
> >    stream = class AbstractResourceStreamWriter()
> >                    {
> >                          public void write(OutputStream output)
> >                         {
> >                               // do your writing
> >                         }
> >                    }
> >
> >     getRequestCycle().setRequestTarget(
> >                     new ResourceStreamRequestTarget( stream
> ).setFileName(
> > "file.xls" )
> >    );
> >
> > johan
> >
> >
> > On Tue, Apr 1, 2008 at 9:31 AM, <dv...@newfoundmarket.com> wrote:
> >
> >> Hello:
> >> I am trying to export dynamically generated excel file.
> >> The generator would send the file.xls to an OutputStream.
> > ...
> >
> > --
> > View this message in context:
> http://www.nabble.com/export-excel-file-via-an-OutputStream-tp16416239p23873774.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
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Export Excel file containing string and rendered component

Posted by Igor Vaynberg <ig...@gmail.com>.
you have the webresponse, can you not simply write into it?

-igor

On Thu, Jun 4, 2009 at 9:49 AM, Frank Silbermann
<fr...@fedex.com> wrote:
>
> I, too, am trying to have my application download MS Excel files.  Until now,
> mine have contained the content of a DataTable, using the code I received
> from the mailing list three years ago:
>
> Button button = new Button("excelExport") {
>    public void onSubmit() {
>        getRequestCycle().setRequestTarget(
>                        new ComponentRequestTarget(dataTable)
>        );
>        WebResponse wr = (WebResponse)getResponse();
>        wr.setContentType( "excel/ms-excel; name="+getMSExcelFilename() );
>        wr.setHeader( "content-disposition",
> "attachment;filename="+getMSExcelFilename() );
>    }
> };
>
> The file downloaded contains an HTML fragment that both MS Excel and MS Word
> can interpret, if one opens the resulting file in those applications.
>
> Now my users told me they would like the download to contain not just the
> data, but the date of its creation.  Is there an easy way to pre-pend an
> arbitrary string to that HTML fragment?  I don't really understand the
> details of Wicket's page rendering process, and looking at the classes I've
> been using there don't seem to be any obvious hooks.
>
>
>
>
>    stream = class AbstractResourceStreamWriter()
>                    {
>                          public void write(OutputStream output)
>                         {
>                               // do your writing
>                         }
>                    }
>
>     getRequestCycle().setRequestTarget(
>                     new ResourceStreamRequestTarget( stream ).setFileName(
> "file.xls" )
>    );
>
> johan
>
>
> On Tue, Apr 1, 2008 at 9:31 AM, <dv...@newfoundmarket.com> wrote:
>
>> Hello:
>> I am trying to export dynamically generated excel file.
>> The generator would send the file.xls to an OutputStream.
> ...
>
> --
> View this message in context: http://www.nabble.com/export-excel-file-via-an-OutputStream-tp16416239p23873774.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
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Export Excel file containing string and rendered component

Posted by Frank Silbermann <fr...@fedex.com>.
I, too, am trying to have my application download MS Excel files.  Until now,
mine have contained the content of a DataTable, using the code I received
from the mailing list three years ago:

Button button = new Button("excelExport") {
    public void onSubmit() {
        getRequestCycle().setRequestTarget(
        		new ComponentRequestTarget(dataTable)
        );
        WebResponse wr = (WebResponse)getResponse();
        wr.setContentType( "excel/ms-excel; name="+getMSExcelFilename() );
        wr.setHeader( "content-disposition",
"attachment;filename="+getMSExcelFilename() );
    }
};

The file downloaded contains an HTML fragment that both MS Excel and MS Word
can interpret, if one opens the resulting file in those applications.

Now my users told me they would like the download to contain not just the
data, but the date of its creation.  Is there an easy way to pre-pend an
arbitrary string to that HTML fragment?  I don't really understand the
details of Wicket's page rendering process, and looking at the classes I've
been using there don't seem to be any obvious hooks.




    stream = class AbstractResourceStreamWriter()
                    {
                          public void write(OutputStream output)
                         {
                               // do your writing
                         }
                    }

     getRequestCycle().setRequestTarget(
                     new ResourceStreamRequestTarget( stream ).setFileName(
"file.xls" )
    );

johan


On Tue, Apr 1, 2008 at 9:31 AM, <dv...@newfoundmarket.com> wrote:

> Hello:
> I am trying to export dynamically generated excel file.
> The generator would send the file.xls to an OutputStream.
...

-- 
View this message in context: http://www.nabble.com/export-excel-file-via-an-OutputStream-tp16416239p23873774.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: export excel file via an OutputStream

Posted by Johan Compagner <jc...@gmail.com>.
stream = class AbstractResourceStreamWriter()
{
public void write(OutputStream output)
{
 // do youre writing
}
}

  getRequestCycle().setRequestTarget(new
ResourceStreamRequestTarget(stream).setFileName("file.xls"));

johan


On Tue, Apr 1, 2008 at 9:31 AM, <dv...@newfoundmarket.com> wrote:

> Hello:
> I am trying to export dynamically generated excel file.
> The generator would send the file.xls to an OutputStream.
>
> In wicket, I am trying to use example as below but
>  how can I connect the OutputStream to the inputstream
> ins.  Pipedoutputstream would block. Using a separate thread
> is not desirable.
>
> public void onClick() {
>
>   IResourceStream stream = new AbstractResourceStream() {
>
>                         public InputStream getInputStream() throws
> ResourceStreamNotFoundException {
>
>
>                             return ins;
>                         }
>
>                         public void close() throws IOException {
>                             ins.close();
>                         }
>                     };
>
>                     getRequestCycle().setRequestTarget(
>                             new
> ResourceStreamRequestTarget(stream).setFileName("file.xls"));

Re: export excel file via an OutputStream

Posted by Igor Vaynberg <ig...@gmail.com>.
see Streams.copy() in wicket utils package

-igor

On Tue, Apr 1, 2008 at 12:31 AM,  <dv...@newfoundmarket.com> wrote:
> Hello:
>  I am trying to export dynamically generated excel file.
>  The generator would send the file.xls to an OutputStream.
>
>  In wicket, I am trying to use example as below but
>   how can I connect the OutputStream to the inputstream
>  ins.  Pipedoutputstream would block. Using a separate thread
>  is not desirable.
>
>  public void onClick() {
>
>    IResourceStream stream = new AbstractResourceStream() {
>
>                          public InputStream getInputStream() throws ResourceStreamNotFoundException {
>
>
>                              return ins;
>                          }
>
>                          public void close() throws IOException {
>                              ins.close();
>                          }
>                      };
>
>                      getRequestCycle().setRequestTarget(
>                              new ResourceStreamRequestTarget(stream).setFileName("file.xls"));

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org