#region 导出Excel
        private void ExportToXls(DataTable dt)
        {
            if (dt != null)
            {
                IReport p = new Report();
                ExcelPage ep = new ExcelPage();
                ep.name = “export.xls”;
                ExcelRow er = new ExcelRow();
                foreach (DataColumn c in dt.Columns)
                {
                    ExcelColumn ec = new ExcelColumn();
                    ec.value = c.ColumnName;
                    er.Columns.Add(ec);
                }
                ep.Rows.Add(er);
                foreach (DataRow row in dt.Rows)
                {
                    ExcelRow er1 = new ExcelRow();
                    foreach (DataColumn c in dt.Columns)
                    {
                        ExcelColumn ec = new ExcelColumn();
                        ec.value = row[c.ColumnName].ToString();
                        er1.Columns.Add(ec);
                    }
                    ep.Rows.Add(er1);
                }
                p.DataSource.Add(ep);
                p.InitData(Context);
            }
        }
        #endregion

版权声明:本文为wuquelin原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/wuquelin/articles/3089877.html