How to display word or excel document in browser window? RRS feed

  • Question

  • We need to display a word document or excel file (dynamically generated from application) inside the browser as part of our Java application. But when we tried to achieve this, it is always showing a popup with options like Open, Save and Save As. We don't want this popup and directly want to show the document in browser window itself (not in corresponding applications like MS Word or MS Excel respectively).

    We have a Java/J2EE application and document (Word or Excel) will be generated at runtime on Server. Once the document is generated, we want to display it in browser window on Client machine. We are able to achieve this for PDF file but for Word (.doc or .docx) and Excel (.xls or .xlsx) files, same code is showing a popup with options Open, Save, Save As.

    Our code contains a Servlet in which response is populated as below

    response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");//MIME Type

    response.setHeader("Content-disposition", "inline; filename=abc.docx");

    response.setContentLength(<file contents size>);

    //put file contents in response output stream

    Below are the MIME types which we tried to use for different types of files

    .doc application/msword
    .docx application/vnd.openxmlformats-officedocument.wordprocessingml.document
    .xls application/
    .xlsx application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
    .pdf application/pdf

    Is there any way to fulfill this requirement? If yes, please share the details.

    Thanks in advance.


    Thursday, August 6, 2015 3:20 AM