ExcelConfig

ExcelConfig类是一个用于设置和生成Excel的配置文件,它支持从GridView或DataTable获取数据。类提供了设置输出文件名、路径、工作表名称、表头和内容的方法,并能根据数据类型自动填充内容。此外,还提供了是否从模板加载、是否存在宏等属性。
摘要由CSDN通过智能技术生成

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Drawing;

/// <summary>
/// 用于设置打印输出的Excel配置文件
/// </summary>
public class ExcelConfig
{
    private object _data = null;
    private bool _isGridView = true;
    private bool _isDataTable = false;

    private bool _isfromtemplate = false;
    private string _exportexcelfilename = "";
    private string _exportexcelfilepath = "";
    private string _templatefilename = "";
    private string _templatefilepath = "";
    private string _sheetname = null;
    private string[] _headertext = null;
    private string[,] _contenttext = null;
    private string _headertitle = "";
    private bool _hasmacro = false;
    private string _macro = "";

    public ExcelConfig()
    {
        this._data = null;
        this._isGridView = false;
        this._isDataTable = false;
        initConfig();
    }
    public ExcelConfig(DataTable dt)
    {
        this._data = dt;
        this._isGridView = false;
        this._isDataTable = true;
        initConfig();
    }
 public ExcelConfig(GridView gv)
 {
        this._data = gv;
        this._isGridView = true;
        this._isDataTable = false;
        initConfig();
 }

    private void initConfig()
    {
       
        this._exportexcelfilename = DateTime.Now.ToString("yyyymmddhhmmss") + ".xls";//默认保存的文件名根据系统时间自动生成
        this._exportexcelfilepath = "~/xls/"; //默认文件输出的路径
        this._templatefilepath = "~/A

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值