c#导出报表

本文详细介绍了如何在C#环境中实现报表的导出功能,包括常见的Excel、PDF等多种格式。从数据处理到文件生成,全面解析关键步骤和技术要点,帮助开发者提升报表导出的效率和质量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NPOI.SS.Util;
using NPOI.SS.UserModel;
using System.Data;
using System.Collections;
using System.IO;
using NPOI.HSSF.UserModel;
using NPOI.HSSF.Util;
using Model;
using WebSite.Tools.Report;

namespace AxxicsWeb.Tools.Report
{
    public class MaterialInReport : CreateExcel
    {
        /// <summary>
        /// 锁定方法
        /// </summary>
        public static readonly Object lockobj = new Object();
        // 单元格格式:默认左对齐
        private ICellStyle style0 = null;
        // 单元格格式:居中
        private ICellStyle style1 = null;
        // 单元格格式:居中 格式(.00)
        private ICellStyle style2 = null;
        // 报表模板文件名
        public static string modeName = "report.xls";
        // 工作簿
        private HSSFWorkbook hssfworkbook = null;
        // 工作表
        private ISheet sheet = null;

        public byte[] GetExcel(Hashtable ht)
        {
            // 所有的slipInfo数据
            IList<SlipInfo> slist = ht["items"] as IList<SlipInfo>;
            // 查询参数:SlipInfo
            SlipInfo param = ht["s"] as SlipInfo;
            // 传票类型
            string slipType = param.SlipType;
            // 表头数据 数组
            string[] headers = null;
            // 存表头的list
            List<List<Hashtable>> data = new List<List<Hashtable>>();
            // 材料入、出库
            if (slipType == "01" || slipType == "02")
                headers = new string[] { "No.", "供应商编号", "供应商名称", "产品编号", "产品名称", "数量", "单位", "入库时间" };
            // 产品入、出库
            else if (slipType == "03" || slipType == "04")
                headers = new string[] { "No.", "客户编号", "客户名称", "产品编号", "产品名称", "数量", "单位", "入库时间" };
            // 材料转成品出库
            else if (slipType == "05")
                headers = new string[] { "No.", "客户编号", "客户名称", "供应商编号", "供应商名称", "产品编号", "产品名称", "数量", "单位", "入库时间" };

            //创建工作簿和工作表
            this.CreateHSworkbook();

            // 创建表头
            IRow row = sheet.CreateRow(2);
            // 列的数量: headers.Count()
            for (int i = 0, max = headers.Count(); i < max; i++)
           
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值