public ActionResult ExportAgentBooking(string Company_Id, string Company_Name)//Altman.Web.BCDAdmin.Models.CompanyInfo argCompanyInfo)
{
if (string.IsNullOrWhiteSpace(Company_Id) || string.IsNullOrWhiteSpace(Company_Name))
{
return View();
} Dictionary<string, object> vDic = new Dictionary<string, object>();
vDic.Add("argCompanyId", Company_Id);//argCompanyInfo.Company_Id);
vDic.Add("argStatus", (int)Altman.Web.Common.Utility.State.Active);
vDic.Add("argGroupType", (int)Altman.Web.Common.Utility.GroupType.AgentBookingGroup); ClientResponse vUserInGroup = ExcuteService("Altman.Services.BCDAdmin.Group", "GetAgentBookingUser", vDic);
DataTable vDT = vUserInGroup["DtUsers"] as DataTable; Common.ExcelHelper vExcelHelper = new ExcelHelper();
MemoryStream vStream = vExcelHelper.ExeportAgentBookingData(vDT);
if (vStream == null)
{
return View();
}
string vFileName = string.Concat(Company_Name, ".xls");
return File(vStream.ToArray(), CONTENTTYPE, vFileName);
}

EXCEL处理类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; using System.IO;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using System.Data;
namespace Altman.Web.BCDAdmin.Common
{ public class ExcelHelper
{
public MemoryStream ExeportAgentBookingData(DataTable vDt)
{
vDt.DefaultView.Sort = "Group_Name desc,Agent_User_Id desc";
vDt = vDt.DefaultView.ToTable();
MemoryStream file = new MemoryStream();
if (vDt == null || vDt.Rows.Count == )
{
return null;
} int vRowIndex = ;
HSSFWorkbook vHssfworkbook = new HSSFWorkbook();
ISheet vSheet1 = vHssfworkbook.CreateSheet();//.GetSheetAt(0);
IRow rowFirst = vSheet1.CreateRow(vRowIndex);
rowFirst.CreateCell().SetCellValue("组名");
rowFirst.CreateCell().SetCellValue("代订人 ");
rowFirst.CreateCell().SetCellValue("被代订人 ");
rowFirst.CreateCell().SetCellValue("Email"); //设置sheet的属性
for (int colCount = ; colCount < ; colCount++)
{
vSheet1.SetColumnWidth(colCount, * );
} vRowIndex++;
foreach(DataRow vRow in vDt.Rows)
{
IRow row = vSheet1.CreateRow(vRowIndex);
string vUser_ID = vRow["User_ID"].AsString();
string vAgent_User_Id = vRow["Agent_User_Id"].AsString();
if (string.IsNullOrWhiteSpace(vUser_ID) && string.IsNullOrWhiteSpace(vAgent_User_Id))
{
continue;
}
row.CreateCell().SetCellValue(vRow["Group_Name"].AsString());
if(!string.IsNullOrWhiteSpace(vUser_ID))//被代订人
{
row.CreateCell().SetCellValue(vRow["User_Name"].AsString());
}
if(!string.IsNullOrWhiteSpace(vAgent_User_Id))//代订人
{
row.CreateCell().SetCellValue(vRow["User_Name"].AsString());
}
row.CreateCell().SetCellValue(vRow["User_Email"].AsString());
vRowIndex++;
}
if (vRowIndex == )
{
return null;
}
vHssfworkbook.Write(file);
return file;
}
}
}

生成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. 就Double、Decimal来说数据计算异常

    场景: 客户提示发料时提示库存不足,可肉眼比对发料数量与库存数量没有一点问题. 但调度跟踪却发现出现“不可思议”的异常. 简单分析: 1.转Decimal再计算没问题.精度较高,存储方法也不一样,所以 ...

  2. 154 Find Minimum in Rotated Sorted Array II

    多写限制条件可以加快调试速度. ======= Follow up for "Find Minimum in Rotated Sorted Array":What if dupli ...

  3. mysql小问题

    报错信息如下: 主要是因为用root用户登录查询其他用户的表,结果这个用户不存在了,所以导致没有权限.临时解决办法,给root赋所有权限: grant all privileges on *.* to ...

  4. IGS_学习笔记10_IREP监控SOA Integration和日志设定(案例)

    20150506 Created By BaoXinjian

  5. PLSQL_Oracle Table Lock表级锁的处理(案例)

    20150506 Created By BaoXinjian

  6. [MySQL] 字符集的选择

    1. Mysql支持的字符集 MySQL服务器可以支持多种字符集,不同的字段都可以使用不同的字符集. 查看所有可用字符集: show character set; select * from info ...

  7. centos6.5安装mysql记录

    1.查看操作系统相关信息. [root@linuxidc ~]# cat /etc/issue CentOS release 6.5 (Final) Kernel \r on an \m [root@ ...

  8. JAVA算数运算符

    算数运算符 序号 算数运算符 含义用法 特殊含义用法 1 + 加法 字符串连接 2 - 减法   3 * 乘法   4 / 除法   5 % 取余   实例: public class Test{ p ...

  9. IP地址漂移的实现与原理

    当前备份软件比较流行,其中用到的关键技术是IP 地址漂移, 实际上IP地址漂移技术是利用共享的“虚拟”IP地址,当本地进行节点切换与路由切换,使另一端的发送和收方端没有感觉到本地节点地址有变化,保证了 ...

  10. 用java程序调用ffmpeg执行视频文件格式转换flv

    用java小例题说明更直观:(可以直接编译运行)环境我在windows平台下测试的...需要在e:/下有ffmpeg.exe;mencoder.exe;drv43260.dll;pncrt.dll共4 ...