Пример #1
0
        /// <summary>
        /// Update the <see cref="CacheItem"/>s.
        /// </summary>
        /// <param name="sourceDataRange">The source range of the data without header row.</param>
        /// <param name="logger">The logger to use to log method calls.</param>
        public void UpdateRecords(ExcelRangeBase sourceDataRange, IFormulaParserLogger logger)
        {
            logger?.LogFunction(nameof(this.UpdateRecords));
            // Remove extra records.
            if (sourceDataRange.Rows < this.Records.Count)
            {
                for (int i = this.Records.Count - 1; i >= sourceDataRange.Rows; i--)
                {
                    this.Records[i].Remove(base.TopNode);
                }
                var count = this.Records.Count - sourceDataRange.Rows;
                if (count > 0)
                {
                    this.Records.RemoveRange(sourceDataRange.Rows, count);
                }
                else
                {
                    this.Records.RemoveAt(sourceDataRange.Rows);
                }
            }

            for (int row = sourceDataRange.Start.Row; row < sourceDataRange.Rows + sourceDataRange.Start.Row; row++)
            {
                int recordIndex     = row - sourceDataRange.Start.Row;
                var rowCells        = new List <object>();
                int cacheFieldIndex = 0;
                for (int column = sourceDataRange.Start.Column; column < sourceDataRange.End.Column + 1; column++)
                {
                    var cacheField = this.CacheDefinition.CacheFields[cacheFieldIndex];
                    var cell       = sourceDataRange.Worksheet.Cells[row, column];
                    // If the cell value is a DateTime, convert it to an date.
                    if (cacheField.SharedItems.ContainsDate == true && cell.Value is double)
                    {
                        rowCells.Add(DateTime.FromOADate((double)cell.Value));
                    }
                    else
                    {
                        rowCells.Add(cell.Value);
                    }
                    cacheFieldIndex++;
                }
                // If the row is within the existing range of cacheRecords, update that cacheRecord. Otherwise, add a new record.
                if (recordIndex < this.Records.Count)
                {
                    this.Records[recordIndex].Update(rowCells, this.CacheDefinition);
                }
                else
                {
                    this.Records.Add(new CacheRecordNode(this.NameSpaceManager, base.TopNode, rowCells, this.CacheDefinition));
                }
            }
            this.Count = this.Records.Count;
        }
Пример #2
0
 /// <summary>
 /// Attaches a logger to the <see cref="FormulaParser"/>.
 /// </summary>
 /// <param name="logger">An instance of <see cref="IFormulaParserLogger"/></param>
 /// <see cref="OfficeOpenXml.FormulaParsing.Logging.LoggerFactory"/>
 public void AttachLogger(IFormulaParserLogger logger)
 {
     _parser.Configure(c => c.AttachLogger(logger));
 }
Пример #3
0
 /// <summary>
 /// Attaches a logger, errors and log entries will be written to the logger during the parsing process.
 /// </summary>
 /// <param name="logger"></param>
 /// <returns></returns>
 public ParsingConfiguration AttachLogger(IFormulaParserLogger logger)
 {
     Require.That(logger).Named("logger").IsNotNull();
     Logger = logger;
     return this;
 }
Пример #4
0
 /// <summary>
 /// Attaches a logger, errors and log entries will be written to the logger during the parsing process.
 /// </summary>
 /// <param name="logger"></param>
 /// <returns></returns>
 public ParsingConfiguration AttachLogger(IFormulaParserLogger logger)
 {
     Require.That(logger).Named("logger").IsNotNull();
     Logger = logger;
     return(this);
 }
Пример #5
0
 /// <summary>
 /// Attaches a logger to the <see cref="FormulaParser"/>.
 /// </summary>
 /// <param name="logger">An instance of <see cref="IFormulaParserLogger"/></param>
 /// <see cref="OfficeOpenXml.FormulaParsing.Logging.LoggerFactory"/>
 public void AttachLogger(IFormulaParserLogger logger)
 {
     _parser.Configure(c => c.AttachLogger(logger));
 }
Пример #6
0
 /// <summary>
 /// if a logger is attached it will be removed.
 /// </summary>
 /// <returns></returns>
 public ParsingConfiguration DetachLogger()
 {
     Logger = null;
     return(this);
 }