Thursday, June 27, 2019

Re: How to generate and download Excel Files with GWT

Hi, Can you please let me know which module did add gwt.xml file to work with WritableWorkbook. I have a situation to work with Excel in GWT but not able to find any module

On Tuesday, 4 May 2010 19:22:28 UTC+5:30, Dima wrote:

I try to create a test.xsl on the server without saving the file on
the server. My application is running fine in hosted mode, but once
compiled and uploud(Tomcat) I get a nasty exception. Probably my
servleturl is not correct.

My code:

    final String link = GWT.getModuleBaseURL() + "myfiledownload";

                          RequestBuilder builder = new

                          try {
                               builder.sendRequest(null, new RequestCallback() {
                            public void onError(Request request, Throwable t) {
                              Window.alert("Error bei getExcel");
                          public void onResponseReceived(Request request,Response response)

                                  if(response.getStatusCode() == 200) {
                            } else if(response.getStatusCode() == 404) {
                              Window.alert("Service not available.");
                         } catch (RequestException re) {
                           GWT.log("Error", re);


<servlet path="/myfiledownload" class="module.server.MyFileServlet"/>

package module.server;

public class MyFileServlet extends HttpServlet {
          private static final long serialVersionUID = 1L;

public void  doGet(HttpServletRequest request, HttpServletResponse
response) throws  IOException {
            try {
              // Get Excel Data
              ByteArrayOutputStream bytes = generateExcelReport();

              // Initialize Http Response Headers
              response.setHeader("Content-disposition", "attachment;

              // Write data on response output stream
              if (bytes != null) {
            } catch (Exception e) {
              response.getWriter().print("An error as occured");

public ByteArrayOutputStream generateExcelReport() throws IOException,

           /* Stream containing excel data */
                ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

                /* Create Excel WorkBook and Sheet */
                WritableWorkbook workBook = Workbook.createWorkbook(outputStream);
                WritableSheet sheet = workBook.createSheet("User List", 0);

                /* Generates Headers Cells */
                WritableFont headerFont = new WritableFont(WritableFont.TAHOMA, 12,
                WritableCellFormat headerCellFormat = new
                sheet.addCell(new Label(1, 1, "LastName", headerCellFormat));
                sheet.addCell(new Label(2, 1, "FirstName", headerCellFormat));

                /* Generates Data Cells */
                WritableFont dataFont = new WritableFont(WritableFont.TAHOMA, 12);
                WritableCellFormat dataCellFormat = new
                int currentRow = 2;

                /* Write & Close Excel WorkBook */

                return outputStream;


Please help my...

You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

No comments:

Post a Comment