public void ExportQueryPrj(HttpContext context) { //接受前端传递参数和数据 string datasource = context.Request["queryResult"]; //序列化后的json字符串 List<QueryXM> queryList = JSONStringToList<QueryXM>(datasource); //反序列化json字符串为list if (queryList.Count > 0) { Workbook workbook = new Workbook();//工作薄 Worksheet worksheet = workbook.Worksheets[0];//工作表 Cells cells = worksheet.Cells;//单元格 //表头部分 cells[0, 0].PutValue("索引值"); cells[0, 1].PutValue("项目ID"); cells[0, 2].PutValue("用地位置"); cells[0, 3].PutValue("项目名称"); cells[0, 4].PutValue("建设单位"); cells[0, 5].PutValue("用地性质"); cells[0, 6].PutValue("用地面积"); cells[0, 7].PutValue("项目类型"); cells[0, 8].PutValue("红线类别"); cells[0, 9].PutValue("用地分类"); cells[0, 10].PutValue("BELONGTFZX"); cells[0, 11].PutValue("TDCRSTATUS"); cells[0, 12].PutValue("TDYT"); cells[0, 13].PutValue("JSYDFL"); //调整宽度 cells.SetColumnWidth(2, 40); cells.SetColumnWidth(3, 60); cells.SetColumnWidth(4, 80); cells.SetColumnWidth(7, 40); cells.SetColumnWidth(8, 20); //内容 for (int i = 0; i < queryList.Count; i++) { cells[i+1, 0].PutValue(queryList[i].OBJECTID); cells[i + 1, 1].PutValue(queryList[i].PrjID); cells[i + 1, 2].PutValue(queryList[i].FADDRESS); cells[i + 1, 3].PutValue(queryList[i].PRJNAME); cells[i + 1, 4].PutValue(queryList[i].FCOMPANY); cells[i + 1, 5].PutValue(queryList[i].YDXZ); cells[i + 1, 6].PutValue(queryList[i].YDMJ); cells[i + 1, 7].PutValue(queryList[i].XMLX); cells[i + 1, 8].PutValue(queryList[i].TYPE); cells[i + 1, 9].PutValue(queryList[i].YDFL); cells[i + 1, 10].PutValue(queryList[i].BELONGTFZX); cells[i + 1, 11].PutValue(queryList[i].TDCRSTATUS); cells[i + 1, 12].PutValue(queryList[i].TDYT); cells[i + 1, 13].PutValue(queryList[i].JSYDFL); cells.SetRowHeight(i + 1, 25); //设置行高 } string filepath= "../Aspose/QueryExcel/项目查询报告"+DateTime.Now.ToString("yyyymmddHHmmss")+".xls"; string fileServerPath = context.Server.MapPath(filepath); if (!File.Exists(fileServerPath)) { var myfile = File.Create(fileServerPath); myfile.Close(); } workbook.Save(fileServerPath); //按照json格式返回前端数据 ResponseResult response = new ResponseResult() { responseMark = 1, responseObject = filepath }; context.Response.Write(new JavaScriptSerializer().Serialize(response)); } }