Ejemplo n.º 1
0
        public void Export(ExportBook book, Stream stream)
        {
            if (stream == null)
            {
                throw new Exception("stream is null");
            }

            FillWorkBook(book);
            _workBook.Write(stream);
        }
Ejemplo n.º 2
0
        public byte[] Export(ExportBook book)
        {
            FillWorkBook(book);

            using (var stream = new MemoryStream())
            {
                _workBook.Write(stream);
                return(stream.ToArray());
            }
        }
Ejemplo n.º 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());
            }
        }
Ejemplo n.º 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);
        }