<强>一、效果如下强>
<强>二,js代码强>
函数export_word(){//导出单词
var url=" czzsca/exportWord.do”;
this.export (url);
}
函数导出(url) {
var currentyear=$ (" # mainYear”) .val () * 1;
var key_columns=[“xh”、“d_name”、“d_unit”、“d_number”、“d_estimate”、“d_lastyear”、“jnjh”、“d_remarks”、“d_depart”、“d_executeunit”);
var value_columns=['序号”、“项目名称”、“单位”,“数量”,“总概算”、“至”+ (currentyear-1) +“年完成”,currentyear +“年计划的,“附注”、“责任部门”、“计划执行单位”);
window.location。href=https://www.yisu.com/zixun/url + " & # 63; key_columns=" + key_columns +”, value_columns=" + value_columns +”,标题=" + currentyear +“年更新改造计划正式计划草案”;
}
<强>三、控制器代码强>
(控制器代码比较长,主要是格式化每一行的数据,主要是往工具类里传List在参数,泛型的List是每一行,弦是每一列)
//导出单词
@RequestMapping ("/exportWord.do”)
@ResponseBody
公共ReturnMsg exportWord (String [] key_columns, String [] value_columns,字符串标题,HttpServletResponse响应){
ReturnMsg rm=new ReturnMsg ();
尝试{
response.setCharacterEncoding(“utf - 8”);
response.setContentType(“应用程序/msexcle”);
响应。setHeader(“附加”,“附件;文件名=" +新字符串(“正式计划草案”.getBytes (“gb2312”)、“ISO8859-1”) + . doc);
List比;内容=new ArrayList比;头=new ArrayList在();
字符串jnjhzh=new BigDecimal (this.map.get (jnjhzh)==null | |”“.equals (this.map.get (“jnjhzh”) + " ") & # 63;“0”: this.map.get (“jnjhzh”) + " ")。RoundingMode.UP setScale (1) + ";
字符串trimpro=new BigDecimal (this.map.get (tzjh)==null | |”“.equals (this.map.get (“tzjh”) + " ") & # 63;“0”: this.map.get (“tzjh”) + " ")。RoundingMode.UP setScale (1) + ";
字符串temp=new BigDecimal (trimpro)。减去(新BigDecimal (jnjhzh)) + ";
如果(“0”.equals(临时)){
temp=" ";
}
头=ExportUtil。getCzzscaList (jnjhzh trimpro、临时);
地图dounit=new HashMap ();
dounit。(“dwlx”, 0);
dounit。(" user_type ", 1);
List