internal GenericExcelExporter(ExcelDocumentCreationOptions options,
                                      Func <dynamic, Dictionary <int, string> > indexRowValues, Func <dynamic, int, object> getValueFromRow)
        {
            _indexRowValues = indexRowValues;

            _getValueFromRow = getValueFromRow;

            _indexedRowValues = new Dictionary <int, string>();

            _includeHeaderRow = options.IncludeHeaderRow;

            _columnsToHide = new List <string>();

            _excelColumnToRowIndex = new Dictionary <int, int>();

            if (options.HiddenColumns != null)
            {
                _columnsToHide = options.HiddenColumns;
            }

            _columnsToIgnore = new List <string>();

            if (options.IgnoredColumns != null)
            {
                _columnsToIgnore = options.IgnoredColumns;
            }

            _columnMapping = new Dictionary <string, string>();

            if (_columnMapping != null)
            {
                _columnMapping = options.ColumnMappings as Dictionary <string, string>;
            }
        }
        public static void SaveRecordsToExcelWorksheet(string fileName, DataTable records,
                                                       Action <ExcelDocumentCreationOptions> options = null)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            if (records == null)
            {
                throw new ArgumentNullException(nameof(records));
            }


            var documentCreationOptions = ExcelDocumentCreationOptions.Default(fileName);

            options?.Invoke(documentCreationOptions);

            using (var document = new ExcelPackage())
            {
                var exporter = new GenericExcelExporter(documentCreationOptions, DataTableExcelExporter.IndexRowValues,
                                                        DataTableExcelExporter.GetValueFromRow);

                exporter.AddRecordsToWorksheet(documentCreationOptions.WorksheetName, records, document);

                documentCreationOptions.ExecuteAfterDocumentCreated(document);
            }
        }