1. public ActionResult ExportAgentBooking(string Company_Id, string Company_Name)//Altman.Web.BCDAdmin.Models.CompanyInfo argCompanyInfo)
  2. {
  3. if (string.IsNullOrWhiteSpace(Company_Id) || string.IsNullOrWhiteSpace(Company_Name))
  4. {
  5. return View();
  6. }
  7.  
  8. Dictionary<string, object> vDic = new Dictionary<string, object>();
  9. vDic.Add("argCompanyId", Company_Id);//argCompanyInfo.Company_Id);
  10. vDic.Add("argStatus", (int)Altman.Web.Common.Utility.State.Active);
  11. vDic.Add("argGroupType", (int)Altman.Web.Common.Utility.GroupType.AgentBookingGroup);
  12.  
  13. ClientResponse vUserInGroup = ExcuteService("Altman.Services.BCDAdmin.Group", "GetAgentBookingUser", vDic);
  14. DataTable vDT = vUserInGroup["DtUsers"] as DataTable;
  15.  
  16. Common.ExcelHelper vExcelHelper = new ExcelHelper();
  17. MemoryStream vStream = vExcelHelper.ExeportAgentBookingData(vDT);
  18. if (vStream == null)
  19. {
  20. return View();
  21. }
  22. string vFileName = string.Concat(Company_Name, ".xls");
  23. return File(vStream.ToArray(), CONTENTTYPE, vFileName);
  24. }

EXCEL处理类:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5.  
  6. using System.IO;
  7. using NPOI.HSSF.UserModel;
  8. using NPOI.SS.UserModel;
  9. using System.Data;
  10. namespace Altman.Web.BCDAdmin.Common
  11. {
  12.  
  13. public class ExcelHelper
  14. {
  15. public MemoryStream ExeportAgentBookingData(DataTable vDt)
  16. {
  17. vDt.DefaultView.Sort = "Group_Name desc,Agent_User_Id desc";
  18. vDt = vDt.DefaultView.ToTable();
  19. MemoryStream file = new MemoryStream();
  20. if (vDt == null || vDt.Rows.Count == )
  21. {
  22. return null;
  23. }
  24.  
  25. int vRowIndex = ;
  26. HSSFWorkbook vHssfworkbook = new HSSFWorkbook();
  27. ISheet vSheet1 = vHssfworkbook.CreateSheet();//.GetSheetAt(0);
  28. IRow rowFirst = vSheet1.CreateRow(vRowIndex);
  29. rowFirst.CreateCell().SetCellValue("组名");
  30. rowFirst.CreateCell().SetCellValue("代订人 ");
  31. rowFirst.CreateCell().SetCellValue("被代订人 ");
  32. rowFirst.CreateCell().SetCellValue("Email");
  33.  
  34. //设置sheet的属性
  35. for (int colCount = ; colCount < ; colCount++)
  36. {
  37. vSheet1.SetColumnWidth(colCount, * );
  38. }
  39.  
  40. vRowIndex++;
  41. foreach(DataRow vRow in vDt.Rows)
  42. {
  43. IRow row = vSheet1.CreateRow(vRowIndex);
  44. string vUser_ID = vRow["User_ID"].AsString();
  45. string vAgent_User_Id = vRow["Agent_User_Id"].AsString();
  46. if (string.IsNullOrWhiteSpace(vUser_ID) && string.IsNullOrWhiteSpace(vAgent_User_Id))
  47. {
  48. continue;
  49. }
  50. row.CreateCell().SetCellValue(vRow["Group_Name"].AsString());
  51. if(!string.IsNullOrWhiteSpace(vUser_ID))//被代订人
  52. {
  53. row.CreateCell().SetCellValue(vRow["User_Name"].AsString());
  54. }
  55. if(!string.IsNullOrWhiteSpace(vAgent_User_Id))//代订人
  56. {
  57. row.CreateCell().SetCellValue(vRow["User_Name"].AsString());
  58. }
  59. row.CreateCell().SetCellValue(vRow["User_Email"].AsString());
  60. vRowIndex++;
  61. }
  62. if (vRowIndex == )
  63. {
  64. return null;
  65. }
  66. vHssfworkbook.Write(file);
  67. return file;
  68. }
  69. }
  70. }

生成Excel直接以流或字节形式发给客户端,无需在服务生成一个实体文件。的更多相关文章

  1. ean13码的生成,python读取csv中数据并处理返回并写入到另一个csv文件中

    # -*- coding: utf-8 -*- import math import re import csv import repr def ean_checksum(eancode): &quo ...

  2. 在.NET中使用EPPlus生成Excel报表 .

    --摘抄自:http://blog.csdn.net/zhoufoxcn/article/details/14112473 在开发.NET应用中可能会遇到需要生成带图表(Chart)的Excel报表的 ...

  3. java 写 Excel(不生成实体文件,写为流的形式)

    java 写 Excel(不生成实体文件,写为流的形式) public String exportReportExcel(String mediaCode, List<SimpleMediaRe ...

  4. Java写Excel(不生成实体文件,写为流的形式)

    java 写 Excel(不生成实体文件,写为流的形式) public String exportReportExcel(String mediaCode, List<SimpleMediaRe ...

  5. npoi生成excel流并在客户端下载(html+后台 )

    //前端页面 <body> <input type="button" value="导出Excel" class="button&q ...

  6. POI导出excel并下载(以流的形式在客户端下载,不保存文件在服务器上)

    import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCellStyle; i ...

  7. ExcelHelper----根据指定样式的数据,生成excel(一个sheet1页)文件流

    /// <summary> /// Excel导出类 /// </summary> public class ExcelHelper { /// <summary> ...

  8. 两种方式实现java生成Excel

    Web应用中难免会遇到需要将数据导出并生成excel文件的需求.同样,对于本博客中的总结,也是建立在为了完成这样的一个需求,才开始去了解其实现形式,并且顺利完成需求的开发,先将实现过程总结于此.本博文 ...

  9. phpexcel生成excel并下载

    Loader::import('PHPExcel.Classes.PHPExcel'); // tp5中只需将phpexcel文件放入extend文件夹中,即可采用该方法引入,需要先 use thin ...

随机推荐

  1. 如何把SQLServer数据库从高版本降级到低版本?

    http://blog.csdn.net/dba_huangzj/article/details/7952403 由于目前还广泛使用着SQLServer2000,很多公司又想使用新的SQLServer ...

  2. SVN:通过Client端打tag

    教你如何使用svnClient打tag~给公司人用的! 1.进入代码主目录 2.右击空白处“TortoiseSVN”—->“Branch/tag” 3.点地址栏右侧的 (选择tags存放目录) ...

  3. linux 鼠标中键粘帖功能?!!

    转载自:http://yjhexy.iteye.com/blog/785564 ubuntu鼠标中键问题,其实也不是什么问题,ubuntu的鼠标中键是用来快速粘贴的,只是windows用惯了,时不时手 ...

  4. 关于Linux中exec的一点心得

    最近在学习linux操作系统中的相关知识,在使用execlp系统调用时,发现了些有趣的东西. 首先,关于execlp函数的用法: int execlp(const char *file, const ...

  5. JavaScript中文字符验证的函数/正则

    /** * 中文字符验证 * @param {} str * @return {Boolean} */ function checkChinese(str) { var re = /[^\u4e00- ...

  6. Google glog 使用

    Google glog 使用 1        简介 Googleglog 库实现了应用级的日志记录,提供了C++ 风格的流操作和各种助手宏. 代码示例: #include <glog/logg ...

  7. Hadoop使用lzo压缩格式

    在hadoop中搭建lzo环境: wget http://www.oberhumer.com/opensource/lzo/download/lzo-2.06.tar.gz export CFLAGS ...

  8. mvc无法找到资源

    昨天装了vs2015,但是第二步没有完成.今天急急忙忙的用13打开一个mvc的项目,但是添加的控制器怎么都不能访问. 无法找到资源. 说明: HTTP 404.您正在查找的资源(或者它的一个依赖项)可 ...

  9. React Native 开发。

    1.react-native run-android 安装 2.react-native start  开启调试端口

  10. JAVA 下拉列表和滚动条

    //下拉列表和滚动条 import java.awt.*; import javax.swing.*; public class Jiemian7 extends JFrame{ JPanel mb1 ...