コード例 #1
0
        public NpoiExcelWorkbook(FileInfo pathToWorkbook, ReportOptions excelOptions)
        {
            pathToWorkbook.ThrowIfNull(nameof(pathToWorkbook));

            _excelOptions = excelOptions.ThrowIfNull(nameof(excelOptions));

            using (var file = new FileStream(pathToWorkbook.FullName, FileMode.Open, FileAccess.Read))
            {
                _workbook = new XSSFWorkbook(file);
            }
            _formulaProvider = ExcelWrapperFactory.CreateFormulaProvider(excelOptions);
        }
コード例 #2
0
        public EpplusExcelWorkbook(ReportOptions excelOptions)
        {
            InitPackageLicence();

            _excelOptions    = excelOptions.ThrowIfNull(nameof(excelOptions));
            _package         = new ExcelPackage();
            _formulaProvider = ExcelWrapperFactory.CreateFormulaProvider(excelOptions);
            _epplusLogger    = new EpplusLogger(_package, ConfigOptions.Logger);

            _epplusLogger.AttachLogger();
            RegisterFunctionModules();
        }
コード例 #3
0
        public static IExcelWorkbook CreateWorkbook(FileInfo outputReportFile,
                                                    ReportOptions reportOptions)
        {
            reportOptions.ThrowIfNull(nameof(reportOptions));

            return(reportOptions.LibraryProvider switch
            {
                ExcelLibraryProvider.NPOI =>
                new NpoiExcelWorkbook(outputReportFile, reportOptions),

                ExcelLibraryProvider.EPPlus =>
                new EpplusExcelWorkbook(outputReportFile, reportOptions),

                _ => throw new ArgumentOutOfRangeException(
                    nameof(reportOptions), reportOptions.LibraryProvider,
                    $"Unknown Excel library provider: '{reportOptions.LibraryProvider.ToString()}'."
                    )
            });
コード例 #4
0
        public static IExcelCellHolder GetCellHolder(IExcelSheet sheet,
                                                     ExcelColumnIndex columnIndex, int rowIndex, ReportOptions excelOptions)
        {
            sheet.ThrowIfNull(nameof(sheet));
            excelOptions.ThrowIfNull(nameof(excelOptions));

            return(excelOptions.CellCreationMode switch
            {
                ExcelCellCreationMode.Default =>
                sheet.GetOrCreateCell(columnIndex, rowIndex),

                ExcelCellCreationMode.Centerized =>
                sheet.GetOrCreateCenterizedCell(columnIndex, rowIndex),

                _ => throw new ArgumentOutOfRangeException(
                    nameof(excelOptions), excelOptions.CellCreationMode,
                    $"Unknown cell creation mode: '{excelOptions.CellCreationMode.ToString()}'."
                    )
            });
コード例 #5
0
 public NpoiExcelWorkbook(ReportOptions excelOptions)
 {
     _excelOptions    = excelOptions.ThrowIfNull(nameof(excelOptions));
     _workbook        = new XSSFWorkbook();
     _formulaProvider = ExcelWrapperFactory.CreateFormulaProvider(excelOptions);
 }
コード例 #6
0
 protected BaseExcelSheet(ReportOptions excelOptions, IExcelFormulaProvider provider)
 {
     _excelOptions   = excelOptions.ThrowIfNull(nameof(excelOptions));
     FormulaProvider = provider.ThrowIfNull(nameof(provider));
 }