Here you go, just change it to excel instead of pdf:
ByteArrayOutputStream pdfOutputStream = new ByteArrayOutputStream();
try {
InputStream is = getClass()
.getResourceAsStream("/helloWorld.jrxml");
JasperDesign design = JRXmlLoader.load(is);
ByteArrayOutputStream bao = pdfOutputStream;
// do something with template
JasperCompileManager.compileReportToStream(design, bao);
ByteArrayInputStream bai = new ByteArrayInputStream(bao
.toByteArray());
Map<String, String> parameters = new HashMap<String, String>();
// parameters.put("issues", issues);
JasperPrint print = JasperFillManager.fillReport(bai,
parameters,
new IssueDataSource(issues));
JasperExportManager.exportReportToPdfStream(print,
pdfOutputStream);
} catch (Exception e) {
// TODO Auto-generated catch block
error(e.getMessage());
}
Link pdfLink = new PdfDynamicLink("link", pdfOutputStream
.toByteArray());
pdfLink.add(new Label("linkText", "Pdf Report"));
add(pdfLink);
import org.apache.wicket.markup.html.link.Link;
import
org.apache.wicket.request.target.resource.ResourceStreamRequestTarget;
import org.apache.wicket.util.resource.IResourceStream;
public class PdfDynamicLink extends Link {
private static final long serialVersionUID = 1L;
byte[] pdf = null;
public PdfDynamicLink(String id, byte[] pdf) {
super(id);
this.pdf = pdf;
}
public void onClick() {
IResourceStream resourceStream = new ByteArrayResourceStream(pdf,
"application/pdf");
getRequestCycle().setRequestTarget(
new ResourceStreamRequestTarget(resourceStream) {
public String getFileName() {
return ("issues.pdf");
}
});
}
}
Bushby wrote:
Does anyone have example code for generating an excel spreadsheet. I am
using Wicket 1.3 and I have used wicket.contrib.jasperreports to
successfully generate pdf files in IE but FireFox returns nothing.
Changing JRPdfResource to JRCsvResource returns a comma separated list but
the type it is returning is html for IE and nothing is showing up for
FireFox. Using JRXlsResource returns nothing in IE or FireFox.
What I am attempting is to have a form submit the query criteria and return
a pdf or excel file.
Code to generate the file
final File reportFile = new File( context.getRealPath( "reports/test.pdf" )
);
return new JRPdfResource( reportFile ).setReportParameters( parameters
).setReportDataSource( customDataSource );
Code on the form
protected void onSubmit( AjaxRequestTarget target, Form form )
{
JRResource pdfResource = new JasperReportUtility().generateReport();
ReportsPanel.this.addOrReplace( new EmbeddedJRReport( "report",
pdfResource ).setOutputMarkupId( true ) );
target.addComponent( ReportsPanel.this );
}
Thanks
Bushby
--
-Wicket for love
Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]