前台js
function gridList() {
var $gridList = $("#gridList");
KaTeX parse error: Expected '}', got 'EOF' at end of input: … url: "{ctx}/citySearch/yixzqyGrid",
height: $(window).height()-178,
colModel: [
{ label: ‘厂商识别代码’,name:‘code’,width:100,align:‘left’},
{ label: ‘企业名称’, name: ‘firm_name’, width: 220, align: ‘left’ },
{ label: ‘首次注册日期’, name: ‘reg_date’, width: 80, align: ‘left’ },
{ label: ‘有效期’, name: ‘valid_date’, width: 80, align: ‘left’ },
{ label: ‘续展日期’, name: ‘appoved_date’, width: 80, align: ‘left’ },
{ label: ‘条码卡卡号’, name: ‘gds’, width: 120, align: ‘left’ },
{ label: ‘发卡日期’, name: ‘gds_date’, width: 80, align: ‘left’, formatter: “date”, formatoptions: { srcformat: ‘Y-m-d’, newformat: ‘Y-m-d’ } },
{ label: ‘企业类别’, name: ‘econname’, width: 120, align: ‘left’ },
{ label: ‘行业分类’, name: ‘jjhymc’, width: 80, align: ‘left’ },
{ label: ‘企业地址’, name: ‘address’, width: 220, align: ‘left’},
{ label: ‘邮政编码’, name: ‘postcode’, width: 80, align: ‘left’ },
{ label: ‘法人’, name: ‘leader’, width: 80, align: ‘left’ },
{ label: ‘法人电话’, name: ‘leader_handset’, width: 100, align: ‘left’ },
{ label: ‘联系人’, name: ‘contactman’, width: 100, align: ‘left’ },
{ label: ‘联系电话’, name: ‘contactman_tele’, width: 100, align: ‘left’ },
{ label: ‘联系手机’, name: ‘contactman_mp’, width: 100, align: ‘left’ },
{ label: ‘注册资金’, name: ‘register_principal’, width: 100, align: ‘left’ },
{label: ‘操作’, name: ‘id’, width: 80, align: ‘left’,hidden:true
,formatter: function (v, options, row) {
return"查看";
}
}
],
pager: “#gridPager”,
sortname: ‘valid_date’,
sortorder:‘asc’,
viewrecords: true,
multiselect: false
});
$("#btn_search").click(function () {
$(“html,body”).animate({ scrollTop: document.body.clientHeight }, 500);
$gridList.jqGrid(‘setGridParam’, {
mtype: ‘POST’,
postData: {
mc: KaTeX parse error: Expected 'EOF', got '#' at position 3: ("#̲mc").val(), …("#regs").val(),
rege:KaTeX parse error: Expected 'EOF', got '#' at position 3: ("#̲rege").val(), …("#yxqs").val(),
yxqe:KaTeX parse error: Expected 'EOF', got '#' at position 3: ("#̲yxqe").val(), …("#xzrqs").val(),
xzrqe:KaTeX parse error: Expected 'EOF', got '#' at position 3: ("#̲xzrqe").val(), …("#areacode").val()
},
}).trigger(‘reloadGrid’);
});
KaTeX parse error: Expected 'EOF', got '#' at position 3: ("#̲btn_download").…{ctx}/citySearch/yixzqyExport";
var data = “mc=”+KaTeX parse error: Expected 'EOF', got '#' at position 3: ("#̲mc").val() …("#regs").val()
+"®e="+KaTeX parse error: Expected 'EOF', got '#' at position 3: ("#̲rege").val() …("#yxqs").val()
+"&yxqe="+KaTeX parse error: Expected 'EOF', got '#' at position 3: ("#̲yxqe").val() …("#xzrqs").val()
+"&xzrqe="+KaTeX parse error: Expected 'EOF', got '#' at position 3: ("#̲xzrqe").val() …("#areacode").val();
$.download(url,data);
});
$("#btn_reset").click(function () {
$(“input[type=text]”).val("");
});
}
Java后台
public void nzxqyExport(String mc,String ywlb,String regs,String rege,String yxqs,String yxqe,String areacode
,HttpServletResponse response) {
RecordSet rs = new RecordSet();
SessionInfo sessionInfo = (SessionInfo) request.getSession().getAttribute(GlobalConstant.SESSION_INFO);
String sql = “select a.code as ‘厂商识别代码’,a.firm_name as ‘企业名称’,a.reg_date as ‘首次注册日期’,a.valid_date as ‘有效期’”
+ “,a.GDS as ‘条码卡卡号’,convert(varchar(10),a.GDS_date,120) as ‘发卡日期’,b.econname as ‘企业类别’,isnull(j.mc,a.t_j_dm) as ‘国民经济行业分类’”
+ “,a.address as ‘企业地址’,a.postcode as ‘邮政编码’,a.leader as ‘法人’ ,a.leader_handset as ‘法人电话’”
+ “,a.contactman as ‘联系人’,a.contactman_tele as ‘联系电话’,a.contactman_mp as ‘联系手机’,a.register_principal as ‘注册资金’”
+ " from tm_qyyw a "
+ " left outer join z_econ b on a.dm=b.econcode "
+ " left outer join z_area c on a.political=c.code "
+ " left outer join z_jjhy j on a.t_j_dm=j.dm "
+ " where a.type not in (‘cancel’,‘beMerged’) and a.isnew=‘1’ ";
if(StringUtil.isEmpty(yxqs) && StringUtil.isEmpty(yxqe)){
sql += " and a.valid_date<DATEADD(MONTH,-2,getdate()) ";
}
if(StringUtil.isNotEmpty(sessionInfo.getOrganCode()) && !sessionInfo.getOrganCode().equals("13010010")){
sql +=" and a.dbd_code='"+sessionInfo.getOrganCode()+"' ";
}
if(StringUtil.isNotEmpty(mc)){
sql += " and (a.code like '%"+mc+"%' or a.firm_name like '%"+mc+"%') ";
}
if(StringUtil.isNotEmpty(ywlb)){
sql += " and a.type='"+ywlb+"' ";
}
if(StringUtil.isNotEmpty(regs)){
sql += " and a.reg_date >= "+Pub.Q(regs);
}
if(StringUtil.isNotEmpty(rege)){
sql += " and a.reg_date <= "+Pub.Q(rege);
}
if(StringUtil.isNotEmpty(yxqs)){
sql += " and a.valid_date>= "+Pub.Q(yxqs);
}
if(StringUtil.isNotEmpty(yxqe)){
sql += " and a.valid_date<= "+Pub.Q(yxqe);
}
if(StringUtil.isNotEmpty(areacode)){
sql += " and a.political in (select code from z_area where pcode="+Pub.Q(areacode)+" or code="+Pub.Q(areacode)+") ";
}
rs.open(sql);
try {
Workbook doc = ExcelUtil2.createWorkBook(rs);
//输出文件
response.reset();
response.setContentType("application/vnd.ms-excel;charset=utf-8");
response.setHeader("Content-Disposition", "attachment;filename="+ new String(("拟注销企业数据.xls").getBytes(), "iso-8859-1"));
OutputStream ostream = response.getOutputStream();
doc.write(ostream);
ostream.flush();
ostream.close();
}catch(Exception e){
e.printStackTrace();
}
}
util类
public class ExcelUtil2 {
/**
* 创建excel文档,
* @param list 数据
* @param keys list中map的key数组集合
* @param columnNames excel的列名
* */
public static Workbook createWorkBook(RecordSet rs) {
// 创建excel工作簿
Workbook wb = new HSSFWorkbook();
// 创建第一个sheet(页),并命名
Sheet sheet = wb.createSheet("sheet1");
// 手动设置列宽。第一个参数表示要为第几列设;,第二个参数表示列的宽度,n为列高的像素数。
for(int i=0;i< rs.fieldsCount();i++){
sheet.setColumnWidth((short) i, (short) (35.7 * 150));
}
// 创建第一行
Row row = sheet.createRow((short) 0);
// 创建两种单元格格式
CellStyle cs = wb.createCellStyle();
CellStyle cs2 = wb.createCellStyle();
// 创建两种字体
Font f = wb.createFont();
Font f2 = wb.createFont();
// 创建第一种字体样式(用于列名)
f.setFontHeightInPoints((short) 10);
f.setColor(IndexedColors.BLACK.getIndex());
f.setBoldweight(Font.BOLDWEIGHT_BOLD);
// 创建第二种字体样式(用于值)
f2.setFontHeightInPoints((short) 10);
f2.setColor(IndexedColors.BLACK.getIndex());
// 设置第一种单元格的样式(用于列名)
cs.setFont(f);
cs.setBorderLeft(CellStyle.BORDER_THIN);
cs.setBorderRight(CellStyle.BORDER_THIN);
cs.setBorderTop(CellStyle.BORDER_THIN);
cs.setBorderBottom(CellStyle.BORDER_THIN);
cs.setAlignment(CellStyle.ALIGN_CENTER);
// 设置第二种单元格的样式(用于值)
cs2.setFont(f2);
cs2.setBorderLeft(CellStyle.BORDER_THIN);
cs2.setBorderRight(CellStyle.BORDER_THIN);
cs2.setBorderTop(CellStyle.BORDER_THIN);
cs2.setBorderBottom(CellStyle.BORDER_THIN);
cs2.setAlignment(CellStyle.ALIGN_CENTER);
//设置列名
for(int i=0;i<rs.fieldsCount();i++){
Cell cell = row.createCell(i);
cell.setCellValue(rs.fields(i));
cell.setCellStyle(cs);
}
//设置每行每列的值
for (int i = 0; i < rs.count(); i++) {
// Row 行,Cell 方格 , Row 和 Cell 都是从0开始计数的
// 创建一行,在页sheet上
Row row1 = sheet.createRow(i+1);
// 在row行上创建一个方格
for(int j=0;j<rs.fieldsCount();j++){
Cell cell = row1.createCell(j);
cell.setCellValue(rs.get(rs.fields(j)));
cell.setCellStyle(cs2);
}
rs.next();
}
return wb;
}
}