生成Excel直接以流或字节形式发给客户端,无需在服务生成一个实体文件。
- 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直接以流或字节形式发给客户端,无需在服务生成一个实体文件。的更多相关文章
- ean13码的生成,python读取csv中数据并处理返回并写入到另一个csv文件中
# -*- coding: utf-8 -*- import math import re import csv import repr def ean_checksum(eancode): &quo ...
- 在.NET中使用EPPlus生成Excel报表 .
--摘抄自:http://blog.csdn.net/zhoufoxcn/article/details/14112473 在开发.NET应用中可能会遇到需要生成带图表(Chart)的Excel报表的 ...
- java 写 Excel(不生成实体文件,写为流的形式)
java 写 Excel(不生成实体文件,写为流的形式) public String exportReportExcel(String mediaCode, List<SimpleMediaRe ...
- Java写Excel(不生成实体文件,写为流的形式)
java 写 Excel(不生成实体文件,写为流的形式) public String exportReportExcel(String mediaCode, List<SimpleMediaRe ...
- npoi生成excel流并在客户端下载(html+后台 )
//前端页面 <body> <input type="button" value="导出Excel" class="button&q ...
- POI导出excel并下载(以流的形式在客户端下载,不保存文件在服务器上)
import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCellStyle; i ...
- ExcelHelper----根据指定样式的数据,生成excel(一个sheet1页)文件流
/// <summary> /// Excel导出类 /// </summary> public class ExcelHelper { /// <summary> ...
- 两种方式实现java生成Excel
Web应用中难免会遇到需要将数据导出并生成excel文件的需求.同样,对于本博客中的总结,也是建立在为了完成这样的一个需求,才开始去了解其实现形式,并且顺利完成需求的开发,先将实现过程总结于此.本博文 ...
- phpexcel生成excel并下载
Loader::import('PHPExcel.Classes.PHPExcel'); // tp5中只需将phpexcel文件放入extend文件夹中,即可采用该方法引入,需要先 use thin ...
随机推荐
- 如何把SQLServer数据库从高版本降级到低版本?
http://blog.csdn.net/dba_huangzj/article/details/7952403 由于目前还广泛使用着SQLServer2000,很多公司又想使用新的SQLServer ...
- SVN:通过Client端打tag
教你如何使用svnClient打tag~给公司人用的! 1.进入代码主目录 2.右击空白处“TortoiseSVN”—->“Branch/tag” 3.点地址栏右侧的 (选择tags存放目录) ...
- linux 鼠标中键粘帖功能?!!
转载自:http://yjhexy.iteye.com/blog/785564 ubuntu鼠标中键问题,其实也不是什么问题,ubuntu的鼠标中键是用来快速粘贴的,只是windows用惯了,时不时手 ...
- 关于Linux中exec的一点心得
最近在学习linux操作系统中的相关知识,在使用execlp系统调用时,发现了些有趣的东西. 首先,关于execlp函数的用法: int execlp(const char *file, const ...
- JavaScript中文字符验证的函数/正则
/** * 中文字符验证 * @param {} str * @return {Boolean} */ function checkChinese(str) { var re = /[^\u4e00- ...
- Google glog 使用
Google glog 使用 1 简介 Googleglog 库实现了应用级的日志记录,提供了C++ 风格的流操作和各种助手宏. 代码示例: #include <glog/logg ...
- Hadoop使用lzo压缩格式
在hadoop中搭建lzo环境: wget http://www.oberhumer.com/opensource/lzo/download/lzo-2.06.tar.gz export CFLAGS ...
- mvc无法找到资源
昨天装了vs2015,但是第二步没有完成.今天急急忙忙的用13打开一个mvc的项目,但是添加的控制器怎么都不能访问. 无法找到资源. 说明: HTTP 404.您正在查找的资源(或者它的一个依赖项)可 ...
- React Native 开发。
1.react-native run-android 安装 2.react-native start 开启调试端口
- JAVA 下拉列表和滚动条
//下拉列表和滚动条 import java.awt.*; import javax.swing.*; public class Jiemian7 extends JFrame{ JPanel mb1 ...