★ How to output web page data as an Excel or Word file

xiaoxiao2021-03-06  48

Replace the <% @ page contenttype = "text / html; charset = GBK" @ Page Contenttype = "Java"%>

<% @ Page ContentType = "Application / VND.ms-Excel; Charset = GBK" Language = "Java"%> // Excel

or

<% @ Page ContentType = "Application / VND.MS-Word; Charset = GBK" Language = "Java"%> // Word

Add a line in front of the page start output data

<%

Response.setHeader ("Content-Disposition", "Attachment; FileName = Result.xls"); // Excel

%>

or

<%

Response.setHeader ("Content-Disposition", "Attachment; FileName = Result.doc"); // Word

%>

Handling of other parts of the page:

Remove the imported CSS file (can be added to the page)

Remove all JavaScript or VBScript

Other code does not need to be changed

转载请注明原文地址:https://www.9cbs.com/read-116203.html

New Post(0)