---
title: "jsp导出excel文件"
author: "softtian1983"
date: "2010-01-13T16:36:01Z"
tags: []
categories: ["Web前端"]
slug: "jsp-excel"
draft: false
lastmod: "2010-01-20T08:36:32Z"
id: 569402
url: "https://twb.iteye.com/blog/569402"
---

jsp中导出excel相当方便，通过简单的js即可。js如下

 

function excelPrint(objStr,tag\_id){  
   var tempStr = document.getElementById(tag\_id).outerHTML;  
   var newWin = window.open();  
   newWin.document.write(tempStr);

   newWin.document.close();  
   newWin.document.execCommand('saveas',true,objStr+'.xls');  
   newWin.window.close();  
 }

 

参数说明：

objStr--导出的excel的默认文件名。

tag\_id---要导出的html标签的id，可以是table，div等