基本信息
源码名称:NPOI操作EXCEL报表(常用类库)
源码大小:0.02M
文件格式:.rar
开发语言:C#
更新时间:2019-02-26
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
NPOI操作EXCEL报表
/*
类:ExportHelper
描述:导出助手类
编 码 人:韩兆新 日期:2015年01月17日
修改记录:
*/
using System;
using System.IO;
using System.Text;
using System.Web;
namespace ExcelReport
{
public static class ExportHelper
{
/// <summary>
/// 导出到本地
/// </summary>
/// <param name="templateFile"></param>
/// <param name="targetFile"></param>
/// <param name="sheetFormatters"></param>
public static void ExportToLocal(string templateFile, string targetFile, params SheetFormatter[] sheetFormatters)
{
#region 参数验证
if (string.IsNullOrWhiteSpace(templateFile))
{
throw new ArgumentNullException("templateFile");
}
if (string.IsNullOrWhiteSpace(targetFile))
{
throw new ArgumentNullException("targetFile");
}
if (!File.Exists(templateFile))
{
throw new FileNotFoundException(templateFile " 文件不存在!");
}
#endregion 参数验证
using (FileStream fs = File.OpenWrite(targetFile))
{
byte[] buffer = Export.ExportToBuffer(templateFile, sheetFormatters);
fs.Write(buffer, 0, buffer.Length);
fs.Flush();
}
}
/// <summary>
/// 导出到Web
/// </summary>
/// <param name="templateFile"></param>
/// <param name="targetFile"></param>
/// <param name="sheetFormatters"></param>
public static void ExportToWeb(string templateFile, string targetFile, params SheetFormatter[] sheetFormatters)
{
#region 参数验证
if (string.IsNullOrWhiteSpace(templateFile))
{
throw new ArgumentNullException("templateFile");
}
if (string.IsNullOrWhiteSpace(targetFile))
{
throw new ArgumentNullException("targetFile");
}
if (!File.Exists(templateFile))
{
throw new FileNotFoundException(templateFile " 文件不存在!");
}
#endregion 参数验证
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.AppendHeader("Content-Disposition",
"attachment;filename=" HttpUtility.UrlEncode(targetFile, Encoding.UTF8));
HttpContext.Current.Response.BinaryWrite(Export.ExportToBuffer(templateFile, sheetFormatters));
HttpContext.Current.Response.End();
}
}
}