You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by drf <da...@gmail.com> on 2010/12/11 19:35:33 UTC

Saving an Excel file using WebResource

I wonder if anyone can provide code for using a WebResource to save an excel
file (created, for instance, using Apache Poi)

The Wicket in Action book gives this example for saving a comma delimited
file:

WebResource export = new WebResource() {

   @Override 
   public IResourceStream getResourceStream() {
      CharSequence discounts = MyDataBase.getInstance() .exportDiscounts();
      return new StringResourceStream(discounts, "text/csv");
   } 

   @Override 
   protected void setHeaders(WebResponse response) {
      super.setHeaders(response); 
      response.setAttachmentHeader("discounts.csv");
   }
}

Which implementation of IResourceStream should be used when saving an Excel
file?
Also, what should the type of file be defined as (application/vnd.ms-excel
?)

Any code examples are very much appreciated

-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Saving-an-Excel-file-using-WebResource-tp3083581p3083581.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: Saving an Excel file using WebResource

Posted by drf <da...@gmail.com>.
This worked:

@Override 
public IResourceStream getResourceStream() {
   HSSFWorkbook workbook = getExcelWorkbook(new HSSFWorkbook());
   byte[] bai = workbook.getBytes();
   ByteArrayResource bar = new ByteArrayResource("application/vnd.ms-excel",
bai);
   return bar.getResourceStream();
} 
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Saving-an-Excel-file-using-WebResource-tp3083581p3083657.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