Showing word or excel document in browser window

We need to display a word document or excel file 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).

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

Thanks in advance. 

July 29th, 2015 3:14am

Hi NitinNahar,

Based on your description, could you tell me how did you want to achieve your result? Did you want to use JAVA or by other methods?

I suggest you be a bit more precise to explain your requirement and provide more information about it so that I can get more accurate solutions to this problem. Im glad to help and follow up your reply.

Regards,

Emi Zhang
TechNet Community Su

Free Windows Admin Tool Kit Click here and download it now
July 30th, 2015 5:36am

Hi Emi,

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/vnd.ms-excel
.xlsx application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.pdf application/pdf

Kindly suggest on how to achieve the requirement.


July 30th, 2015 11:32pm

Hi NitinNahar,

In your code, if the file is word you set the response content type to application/vnd.openxmlformats-officedocument.wordprocessingml.document. Based on the type name, we can know that this function will open the word file by calling wordprocessingml module.

In your scenario, the PDF file works properly, it is because application/pdf type dont call any module to open it. So you can change the response content type to application/msword when the file is word. Maybe it can work.

Please try it and check if it works for you.

Regards,

Emi Zhang
TechNet Community Su

Free Windows Admin Tool Kit Click here and download it now
July 31st, 2015 3:49am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics