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. 减小Gcc编译程序的体积

    众所周知,Gcc编译的原始程序一般很大,其实有几种方法能大大减小目标代码的体积,一般有以下几种方法. 基本知识来源:http://www.mingw.org/wiki/Large_executable ...

  2. [系统集成] CI持续集成项目简介

    一.问题的产生 公司的多个部门围绕着产品开发.测试.发布.维护,设置有不同的岗位和系统,这些岗位和系统缺少有效的整合,没有实现自动化,效率不是很高,因此就有了CI(持续集成)的项目需求. 二.解决方案 ...

  3. 81 Search in Rotated Sorted Array II

    Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this ...

  4. Android的CursorLoader用法小结

    工作内容集中到Contact模块,这个应用查询数据的地方很多,其使用了CursorLoader这个工具大大简化了代码复杂度.Android自3.0提供了Loader机制,当时google的API只是简 ...

  5. Hadoop MapReduce编程学习

    一直在搞spark,也没时间弄hadoop,不过Hadoop基本的编程我觉得我还是要会吧,看到一篇不错的文章,不过应该应用于hadoop2.0以前,因为代码中有  conf.set("map ...

  6. phpmyadmin数据库导入出错

    SQL 查询: -- phpMyAdmin SQL Dump-- version 3.5.1-- http://www.phpmyadmin.net---- 主机: localhost-- 生成日期: ...

  7. 【JavaScript】允许IE8使用placeholder

    var placeholder = function ($element) { var $ = window.jQuery; var version = parseFloat($.browser.ve ...

  8. 过滤3个字节以上的utf-8字符

    /** * 过滤掉超过3个字节的UTF8字符 * @param text * @return * @throws UnsupportedEncodingException */ public stat ...

  9. View的缩放操作--CGAffineTransformMakeScale:

    __weak UIImageView *weekImage = imageView; imageView.transform = CGAffineTransformMakeScale(0.1, 0.1 ...

  10. jquery ajax事件

    $.ajax({ type : 'POST', url : 'user.php', data : $('form').serialize(), success : function (response ...