protected sealed override byte[] CreateExcelData(ExcelExporter exporter, OutputData outputData)
        {
            byte[] data = null;
            switch (outputData.OutputType)
            {
                case SourceOutputType.ToolkitObject:
                case SourceOutputType.Object:
                    ObjectListModel model = outputData.Data as ObjectListModel;
                    if (model != null)
                        data = exporter.Export(model);
                    break;
                case SourceOutputType.DataSet:
                    data = exporter.Export(outputData.Data.Convert<DataSet>());
                    break;
            }

            return data;
        }
 protected sealed override byte[] CreateExcelData(ExcelExporter exporter, OutputData outputData)
 {
     byte[] data = exporter.CreateExcelTemplate();
     return data;
 }
Ejemplo n.º 3
0
        public static byte[] ExcelReport(string strFileName, Tk5ListMetaData metaInfos, ImportError importError)
        {
            MemoryStream  ms       = new MemoryStream();
            ExcelExporter exporter =
                new ExcelExporter(false, ExcelContentFormat.DefaultHeader, ExcelContentFormat.DefaultContent, metaInfos);

            using (ms)
            {
                string sheetName = metaInfos.Table.TableDesc;
                //HSSFWorkbook newWorkbook = exporter.CreateWorkbookTemplate();
                //HSSFSheet newSheet = (HSSFSheet)newWorkbook.CreateSheet(sheetName);
                IWorkbook workBook = null;
                ISheet    sheet    = null;
                Dictionary <string, int> indexOfName = new Dictionary <string, int>();
                int i = 0;
                foreach (var info in metaInfos.Table.TableList)
                {
                    indexOfName.Add(info.DisplayName, i);
                    i++;
                }

                string fileExt = Path.GetExtension(strFileName);
                using (FileStream file = new FileStream(strFileName, FileMode.Open, FileAccess.Read))
                {
                    if (fileExt == ".xls")
                    {
                        workBook = new HSSFWorkbook(file);
                    }
                    else if (fileExt == ".xlsx")
                    {
                        workBook = new XSSFWorkbook(file);
                    }
                }

                sheet = workBook.GetSheet(sheetName);


                IDrawing part = sheet.CreateDrawingPatriarch();

                var res = (from err in importError
                           select err.IndexOfRow).Distinct();

                int[] arr = new int[sheet.LastRowNum];
                for (int index = sheet.FirstRowNum + 1, j = 0; index <= sheet.LastRowNum; index++)
                {
                    arr[j] = index;
                    j++;
                }

                int[] arrExc = arr.Except(res).ToArray();

                foreach (var err in importError)
                {
                    IRow            row     = sheet.GetRow(err.IndexOfRow);
                    IComment        comment = null;
                    ICell           cell    = row.GetCell(indexOfName[err.ColumnName]);
                    ICreationHelper factory = workBook.GetCreationHelper();
                    IClientAnchor   anchor  = null;
                    anchor           = factory.CreateClientAnchor();
                    anchor.Col1      = cell.ColumnIndex + 2;
                    anchor.Col2      = cell.ColumnIndex + 4;
                    anchor.Row1      = row.RowNum;
                    anchor.Row2      = row.RowNum + 3;
                    comment          = part.CreateCellComment(anchor);
                    comment.Author   = "mitu";
                    comment.String   = new HSSFRichTextString(err.ErrorMsg);
                    cell.CellComment = comment;
                }

                int counter = 0;
                foreach (var rowNum in res)
                {
                    sheet.ShiftRows(rowNum, rowNum, 1 - rowNum + counter);
                    counter++;
                }

                for (int rowNum = counter + 1; rowNum <= sheet.LastRowNum; rowNum++)
                {
                    IRow row = sheet.GetRow(rowNum);
                    sheet.RemoveRow(row);
                }

                workBook.Write(ms);
                ms.Flush();
                byte[] filedata = ms.ToArray();
                using (FileStream fs = new FileStream(@"C:\Users\zll\Downloads\ImportReport.xls", FileMode.Create))
                {
                    BinaryWriter bw = new BinaryWriter(fs);
                    bw.Write(filedata);
                    bw.Close();
                    fs.Close();
                }
                return(filedata);
            }
        }
 protected override byte[] CreateExcelData(ExcelExporter exporter, OutputData outputData)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 5
0
        public static byte[] ExcelReport(string strFileName, Tk5ListMetaData metaInfos, ImportError importError)
        {
            MemoryStream ms = new MemoryStream();
            ExcelExporter exporter = 
                new ExcelExporter(false, ExcelContentFormat.DefaultHeader, ExcelContentFormat.DefaultContent, metaInfos);

            using (ms)
            {
                IWorkbook workBook;
                ISheet sheet;

                ReadExcle(strFileName, metaInfos.Table.TableDesc, out workBook, out sheet);
                PostilAdd(metaInfos, importError, workBook, sheet);
                RowFilter(importError, sheet);
            
                workBook.Write(ms);
                byte[] filedata = ms.ToArray();
                ms.Flush();

                using (FileStream fs = new FileStream(@"C:\Users\zll\Downloads\ImportReport.xls", FileMode.Create))
                {
                    BinaryWriter bw = new BinaryWriter(fs);
                    bw.Write(filedata);
                    bw.Close();
                    fs.Close();
                }

                return filedata;
            }

        }