예제 #1
0
        /// <summary>
        /// Renders the value of the column.
        /// </summary>
        /// <param name="defintion"> The CSV definition. </param>
        /// <param name="value"> The value to render. </param>
        /// <param name="culture"> the culture to render in. </param>
        /// <param name="formatter"> The formatter to use for rendering the value into the cell. </param>
        /// <returns>A string that can be directly written into the CSV file. </returns>
        protected override string OnRender(ICsvDefinition defintion, IEnumerable <TArray> value, CultureInfo culture, IStringFormatter formatter)
        {
            var values = value.Select(e => CleanAndFormatValue(defintion, e)).ToArray();

            var element = string.Join(this.ElementDelimiter, values);

            return(formatter.FormatStringCell(element, defintion.RemoveNewLineCharacters));
        }
예제 #2
0
        protected override string OnRender(ICsvDefinition defintion, string value, CultureInfo culture, IStringFormatter formatter)
        {
            var text = this.Format(value ?? string.Empty, culture);

            if (this.ForceNumberToTextFormatting)
            {
                return(formatter.FormatForcedExcelStringCell(text, defintion.RemoveNewLineCharacters));
            }

            return(formatter.FormatStringCell(text, defintion.RemoveNewLineCharacters));
        }
예제 #3
0
        private IEnumerable <string> ProcessElementsByHeaderNames(IEnumerable <CompositeColumnValue <TValue> > collection, CultureInfo culture, IStringFormatter formatter)
        {
            if (this.headers.Length == 0)
            {
                this.headers = GetHeaderNames(collection);
            }

            foreach (var header in this.headers)
            {
                var column = collection.SingleOrDefault(c => c.HeaderName == header.Name);
                if (column == null && !this.AllowUndefinedColumnsInCollection)
                {
                    throw new KeyNotFoundException("The header key '" + header + "' was not found in the composite collection.");
                }
                else if (column == null && this.AllowUndefinedColumnsInCollection)
                {
                    yield return(formatter.FormatStringCell(this.Format(default(TValue), culture)));
                }
                else
                {
                    yield return(formatter.FormatStringCell(this.Format(column.Value, culture)));
                }
            }
        }
예제 #4
0
 private string GetColumnHeaderWithoutEnters(Header header)
 {
     return(formatter.FormatStringCell(header.Name, true));
 }