예제 #1
0
        private string WriteHeaderRow(ExcelOutputTextFormat Format, bool hasTextQ, int row, CultureInfo ci)
        {
            var sb = new StringBuilder();

            for (int col = _fromCol; col <= _toCol; col++)
            {
                if (hasTextQ)
                {
                    sb.Append(Format.TextQualifier);
                }
                var v = GetCellStoreValue(row, col);
                sb.Append(ValueToTextHandler.GetFormattedText(v._value, _workbook, v._styleId, false, ci));
                if (hasTextQ)
                {
                    sb.Append(Format.TextQualifier);
                }
                if (col < _toCol)
                {
                    sb.Append(Format.Delimiter);
                }
            }
            if (row != _toRow)
            {
                sb.Append(Format.EOL);
            }
            return(sb.ToString());
        }
        public override string GetFormat(object value, string format)
        {
            var styles = _package.Workbook.Styles;

            ExcelNumberFormatXml.ExcelFormatTranslator ft = null;
            foreach (var f in styles.NumberFormats)
            {
                if (f.Format == format)
                {
                    ft = f.FormatTranslator;
                    break;
                }
            }
            if (ft == null)
            {
                ft = new ExcelNumberFormatXml.ExcelFormatTranslator(format, -1);
            }
            return(ValueToTextHandler.FormatValue(value, ft, format, ft.NetFormat));
        }
예제 #3
0
 /// <summary>
 /// Applies the filter, hiding rows not matching the filter columns
 /// </summary>
 public void ApplyFilter()
 {
     foreach (var column in Columns)
     {
         column.SetFilterValue(_worksheet, Address);
     }
     for (int row = Address._fromRow + 1; row <= _address._toRow; row++)
     {
         var rowInternal = ExcelRow.GetRowInternal(_worksheet, row);
         rowInternal.Hidden = false;
         foreach (var column in Columns)
         {
             var value = _worksheet.GetCoreValueInner(row, Address._fromCol + column.Position);
             var text  = ValueToTextHandler.GetFormattedText(value._value, _worksheet.Workbook, value._styleId, false);
             if (column.Match(value._value, text) == false)
             {
                 rowInternal.Hidden = true;
                 break;
             }
         }
     }
 }
예제 #4
0
        private string GetText(ExcelOutputTextFormat Format, int maxFormats, CultureInfo ci, int row, int col, out bool isText)
        {
            var v = GetCellStoreValue(row, col);

            var ix = col - _fromCol;

            isText = false;
            string fmt;

            if (ix < maxFormats)
            {
                fmt = Format.Formats[ix];
            }
            else
            {
                fmt = "";
            }
            string t;

            if (string.IsNullOrEmpty(fmt))
            {
                if (Format.UseCellFormat)
                {
                    t = ValueToTextHandler.GetFormattedText(v._value, _workbook, v._styleId, false, ci);
                    if (!ConvertUtil.IsNumericOrDate(v._value))
                    {
                        isText = true;
                    }
                }
                else
                {
                    if (ConvertUtil.IsNumeric(v._value))
                    {
                        t = ConvertUtil.GetValueDouble(v._value).ToString("r", ci);
                    }
                    else if (v._value is DateTime date)
                    {
                        t = date.ToString("G", ci);
                    }
                    else
                    {
                        t      = v._value.ToString();
                        isText = true;
                    }
                }
            }
            else
            {
                if (fmt == "$")
                {
                    if (Format.UseCellFormat)
                    {
                        t = ValueToTextHandler.GetFormattedText(v._value, _workbook, v._styleId, false, ci);
                    }
                    else
                    {
                        t = v._value.ToString();
                    }
                    isText = true;
                }
                else if (ConvertUtil.IsNumeric(v._value))
                {
                    t = ConvertUtil.GetValueDouble(v._value).ToString(fmt, ci);
                }
                else if (v._value is DateTime date)
                {
                    t = date.ToString(fmt, ci);
                }
                else if (v._value is TimeSpan ts)
                {
#if NET35
                    t = ts.Ticks.ToString(ci);
#else
                    t = ts.ToString(fmt, ci);
#endif
                }
                else
                {
                    t      = v._value.ToString();
                    isText = true;
                }
            }
            return(t);
        }