static SeedTableBase GetSeedTable(IExcelData excelData, string sheetName) { var seedTable = excelData.GetSeedTable(sheetName, 2, 3, null, "ID", null); if (seedTable.Errors.Count != 0) { var skipExceptions = seedTable.Errors.Where(error => error is NoIdColumnException); if (skipExceptions.Count() != 0) { foreach (var error in skipExceptions) { Console.WriteLine($" skip: {error.Message}"); } } else { foreach (var error in seedTable.Errors) { Console.WriteLine($" ERROR: {error.Message}"); } throw new CannotContinueException(); } } return(seedTable); }
static SeedTableBase GetSeedTable(IExcelData excelData, string sheetName, CommonOptions options, SheetNameWithSubdivide subdivide) { var seedTable = excelData.GetSeedTable(sheetName, subdivide.ColumnNamesRow ?? options.columnNamesRow, subdivide.DataStartRow ?? options.dataStartRow, options.ignoreColumns, subdivide.KeyColumnName, options.versionColumn); if (seedTable.Errors.Count != 0) { var skipExceptions = seedTable.Errors.Where(error => error is NoIdColumnException); if (skipExceptions.Count() != 0) { foreach (var error in skipExceptions) { WriteInfo($" skip: {error.Message}"); } } else { foreach (var error in seedTable.Errors) { WriteInfo($" ERROR: {error.Message}"); } throw new CannotContinueException(); } } return(seedTable); }
/// <summary> /// Sets the excel styler and other injections needed /// </summary> /// <param name="excelData">The excel package and worksheet</param> /// <param name="excelStyler">The excel class to add styling to cells</param> /// <param name="dictionaryManager">Dictionary manager to get config dictionaries</param> /// <param name="logger">Logger to record messages</param> public ExcelFormatter(IExcelData excelData, IExcelStyler excelStyler, IDictionaryManager dictionaryManager , ILogger <ExcelFormatter> logger) { _worksheet = excelData.Worksheet; _package = excelData.Package; _styler = excelStyler; _logger = logger; // dictionary for null cells _nullCellDictionary = dictionaryManager.GetIntDictionary("NullColumns"); if (_nullCellDictionary == null) { const string error = "The dictionary for columns is null. Ensure the configuration file is correct"; _logger.LogError(error); throw new NullReferenceException(error); } // dictionary for incorrect date times _columnDateTimeDictionary = dictionaryManager.GetIntDictionary("IncorrectTimeColumns"); if (_columnDateTimeDictionary == null) { const string error = "The dictionary for before check columns is null. Ensure the configuration file is correct"; _logger.LogError(error); throw new NullReferenceException(error); } }
static DateTime ExcelToSeedCore(IExcelData excelData, string file, FromOptions options, DateTime startTime, DateTime previousTime) { Log(" sheets"); var fileName = Path.GetFileName(file); var sheetsConfig = new SheetsConfig(options.only, options.ignore, options.subdivide, options.primary, options.mapping, options.alias); foreach (var sheetName in excelData.SheetNames) { var yamlTableName = sheetsConfig.YamlTableName(fileName, sheetName); if (yamlTableName == sheetName) { Log($" {yamlTableName}"); } else { Log($" {yamlTableName} <- {sheetName}"); } if (!sheetsConfig.IsUseSheet(fileName, sheetName, yamlTableName, OnOperation.From)) { Log(" ignore", "skip"); continue; } var subdivide = sheetsConfig.subdivide(fileName, yamlTableName, OnOperation.From); var seedTable = GetSeedTable(excelData, sheetName, options, subdivide); if (seedTable.Errors.Count != 0) { continue; } new YamlData( seedTable.ExcelToData(options.requireVersion), subdivide.NeedSubdivide, subdivide.CutPrefix, subdivide.CutPostfix, subdivide.SubdivideFilename, options.format, options.delete, options.yamlColumns ).WriteTo( yamlTableName, options.output, options.seedExtension ); var now = DateTime.Now; DurationLog(" write-time", previousTime, now); previousTime = now; } return(previousTime); }
public AdministracionController(IUnitOfWork uow, ILineaRepository lineasRepository, IModeloRepository modelosRepository, IMaterialRepository materialRepository, ICategoriaRepository categoriaRepository, ICostoRepository costosRepository, IDepartamentoRepository departamentosRepository, ICentroCostoRepository centrosRepository, IExcelData manager, IFichaTecnicaRepository fichasRepo) { _uow = uow; _lineasDb = lineasRepository; _modelosDb = modelosRepository; _materialesDb = materialRepository; _categoriasDb = categoriaRepository; _costosDb = costosRepository; _departamentosDb = departamentosRepository; _centrosDb = centrosRepository; _fichasDb = fichasRepo; _manager = manager; }
public IExcelResult Write(IExcelData data, string path) { foreach (var inform in data.Table.Data) { this.XLApplication .Workbooks[data.CurrentWorkBook] .Worksheets[data.CurrentSheet] .Cells[inform.Key.X, inform.Key.Y] = inform.Value; } this.XLApplication .Workbooks[data.CurrentWorkBook] .SaveAs(path); return(new ExcelResult()); }
public Presenter(IExcelData view) { this.view = view; Initialize(); }
static DateTime SeedToExcelCore(IExcelData excelData, string file, ToOptions options, DateTime startTime, DateTime previousTime) { Log(" sheets"); var fileName = Path.GetFileName(file); var sheetsConfig = new SheetsConfig(options.only, options.ignore, null, null, options.mapping, options.alias); var yamlDataCache = new Dictionary <string, YamlData>(); // aliasのため同テーブルはキャッシュする foreach (var sheetName in excelData.SheetNames) { var yamlTableName = sheetsConfig.YamlTableName(fileName, sheetName); if (yamlTableName == sheetName) { Log($" {yamlTableName}"); } else { Log($" {yamlTableName} -> {sheetName}"); } if (!sheetsConfig.IsUseSheet(fileName, sheetName, yamlTableName, OnOperation.To)) { Log(" ignore", "skip"); continue; } var subdivide = sheetsConfig.subdivide(fileName, yamlTableName, OnOperation.To); var seedTable = GetSeedTable(excelData, sheetName, options, subdivide); if (seedTable.Errors.Count != 0) { continue; } YamlData yamlData = null; if (!yamlDataCache.TryGetValue(yamlTableName, out yamlData)) { try { yamlData = YamlData.ReadFrom(yamlTableName, options.seedInput, options.seedExtension, subdivide.KeyColumnName); yamlDataCache[yamlTableName] = yamlData; } catch (FileNotFoundException exception) { Log(" skip", $"seed file [{exception.FileName}] not found"); continue; } } try { seedTable.DataToExcel(yamlData.Data, options.delete); } catch (IdParseException exception) { WriteInfo($" ERROR: {exception.Message}"); throw new CannotContinueException(); } var now = DateTime.Now; DurationLog(" write-time", previousTime, now); previousTime = now; } // 数式を再計算して結果をキャッシュする if (options.calcFormulas && excelData is EPPlus.ExcelData) { ((EPPlus.ExcelData)excelData).Calculate(); } if (options.output.Length == 0) { excelData.Save(); Log(" write-path", "overwrite"); } else { var writePath = Path.Combine(options.output, file); Log(" write-path", writePath); if (!Directory.Exists(options.output)) { Directory.CreateDirectory(options.output); } excelData.SaveAs(writePath); } var end = DateTime.Now; DurationLog(" write-time", previousTime, end); return(end); }
protected BaseExcelWriter(IExcelData excelData, IExcelStyler excelStyler) { _excelData = excelData; _excelStyler = excelStyler; }
public ExcelStyler(IExcelData excelData) { _excelData = excelData; }
/// <summary> /// ExcelStyler setup constructor. /// Takes a worksheet which is the sheet to engaged with to apply the styling too /// </summary> /// <param name="excelData"></param> public ExcelStyler(IExcelData excelData) { _worksheet = excelData.Worksheet; }
public ExcelWriter(IExcelData excelData, IExcelStyler excelStyler) : base(excelData, excelStyler) { }
public HomeController() { excelData = new ExcelData(); }