コード例 #1
0
        public void Export(ExportBook book, Stream stream)
        {
            if (stream == null)
            {
                throw new Exception("stream is null");
            }

            FillWorkBook(book);
            _workBook.Write(stream);
        }
コード例 #2
0
        public byte[] Export(ExportBook book)
        {
            FillWorkBook(book);

            using (var stream = new MemoryStream())
            {
                _workBook.Write(stream);
                return(stream.ToArray());
            }
        }
コード例 #3
0
        private void FillWorkBook(ExportBook book)
        {
            if (!book.Sheets?.Any() ?? true)
            {
                throw new Exception("sheets is empty");
            }

            _workBook = WorkbookGenerator.GetIWorkbook(book.Ext);
            foreach (var item in book.Sheets)
            {
                this.CreateSheet(item.Data.GetType().GetGenericArguments()[0], item.SheetName, item.Title, item.Data?.ToList(), item.FilterColumn?.ToList());
            }
        }
コード例 #4
0
        public Stream Export(ExportBook book, Stream stream)
        {
            if (stream == null)
            {
                throw new Exception("stream is null");
            }

            if (!book.Sheets?.Any() ?? true)
            {
                throw new Exception("sheets is empty");
            }

            IWorkbook workbook = WorkbookGenerator.GetIWorkbook(book.Ext);

            foreach (var item in book.Sheets)
            {
                this.CreateSheet(workbook, item.SheetName, item.Title, item.Data, item.FilterColumn);
            }

            workbook.Write(stream);
            workbook.Close();
            return(stream);
        }