예제 #1
0
        /// <summary>
        /// 分页导出到 Excel.
        /// </summary>
        /// <param name="paged">分页的 Exportable.</param>
        /// <param name="name">导出目标 sheet 的名称.</param>
        /// <param name="zip">导出目标流.</param>
        /// <param name="partNameFormat">分页文件命名格式 {0} 代表编号,必须至少包含一个 {0},否则会出现命名冲突..</param>
        /// <param name="callback">导出回调.</param>
        /// <returns>this, 以支持链式操作.</returns>
        public Exporter ExportToExcelByPage(PagedExportable paged, string name, ZipOutputStream zip, string partNameFormat, ExportCallback callback)
        {
            var pageIndex = 0;

            while (paged.NextRow(0))
            {
                var fileName = string.Format(partNameFormat, ++pageIndex);
                var entry    = new ZipEntry(fileName);
                entry.DateTime = DateTime.Now;
                zip.PutNextEntry(entry);

                try
                {
                    this.NewExcel()
                    .NewSheet(name)
                    .UnionHeader(paged, callback)
                    .DoUnion(paged, callback)
                    .WriteTo(zip);
                }
                finally
                {
                    this.CloseExcel();
                }

                paged.NextPage(pageIndex);
            }

            return(this);
        }
예제 #2
0
        /// <summary>
        /// 分页导出到 Excel.
        /// </summary>
        /// <param name="exportable">可导出对象.</param>
        /// <param name="name">导出目标 sheet 的名称.</param>
        /// <param name="pageSize">每页的大小.</param>
        /// <param name="zip">导出目标流.</param>
        /// <param name="partNameFormat">分页文件命名格式 {0} 代表编号,必须至少包含一个 {0},否则会出现命名冲突..</param>
        /// <param name="callback">导出回调.</param>
        /// <returns>this, 以支持链式操作.</returns>
        public Exporter ExportToExcelByPage(IExportable exportable, string name, int pageSize, ZipOutputStream zip, string partNameFormat, ExportCallback callback)
        {
            var paged = new PagedExportable(exportable as IExportHeader, exportable, pageSize);

            return(ExportToExcelByPage(paged, name, zip, partNameFormat, callback));
        }