Example #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandValue" /> class.
 /// </summary>
 /// <param name="func">The function.</param>
 /// <param name="valueKind">Kind of the value.</param>
 /// <param name="valueFormat">The value format.</param>
 public CommandValue(Func <IExcelContext, Collection <string>, object, bool> func, CellValueKind valueKind, Func <IExcelContext, string> valueFormat = null)
 {
     When        = When.Normal;
     Func        = func;
     ValueKind   = valueKind;
     ValueFormat = valueFormat;
 }
Example #2
0
        public static object GetCellsValue(this IExcelContext ctx, string cells, CellValueKind valueKind = CellValueKind.Value)
        {
            var range = ((ExcelContext)ctx).WS.Cells[ctx.DecodeAddress(cells)];

            switch (valueKind)
            {
            case CellValueKind.Value: return(range.Value);

            case CellValueKind.Text: return(range.Text);

            case CellValueKind.AutoFilter: return(range.AutoFilter);

            case CellValueKind.Comment: return(range.Comment.Text);

            case CellValueKind.ConditionalFormattingMore: return(null);

            case CellValueKind.Formula: return(range.Formula);

            case CellValueKind.FormulaR1C1: return(range.FormulaR1C1);

            case CellValueKind.Hyperlink: return(range.Hyperlink);

            case CellValueKind.Merge: return(range.Merge);

            case CellValueKind.StyleName: return(range.StyleName);

            default: throw new ArgumentOutOfRangeException(nameof(valueKind));
            }
        }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CellValue" /> struct.
 /// </summary>
 /// <param name="cells">The cells.</param>
 /// <param name="value">The value.</param>
 /// <param name="valueKind">Kind of the value.</param>
 /// <param name="valueFormat">The value format.</param>
 /// <exception cref="ArgumentNullException">cells</exception>
 public CellValue(string cells, object value, CellValueKind valueKind = CellValueKind.Value, string valueFormat = null)
 {
     When        = When.Normal;
     Cells       = cells ?? throw new ArgumentNullException(nameof(cells));
     ValueType   = value?.GetType();
     Value       = value?.SerializeValue(ValueType);
     ValueKind   = valueKind;
     ValueFormat = valueFormat;
 }
Example #4
0
 public CellsValue(string cells, object value, CellValueKind valueKind = CellValueKind.Value)
 {
     if (string.IsNullOrEmpty(cells))
     {
         throw new ArgumentNullException(nameof(cells));
     }
     When      = When.Normal;
     Cells     = cells;
     Value     = value?.ToString();
     ValueKind = valueKind;
     ValueType = value?.GetType();
 }
Example #5
0
 public CellsValue(Address r, int row, int col, object value, CellValueKind valueKind = CellValueKind.Value)
     : this(ExcelService.GetAddress(r, row, col), value, valueKind)
 {
 }
Example #6
0
 public CellsValue(Address r, int fromRow, int fromCol, int toRow, int toCol, object value, CellValueKind valueKind = CellValueKind.Value)
     : this(ExcelService.GetAddress(r, fromRow, fromCol, toRow, toCol), value, valueKind)
 {
 }
Example #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandValue"/> class.
 /// </summary>
 /// <param name="func">The function.</param>
 /// <param name="valueKind">Kind of the value.</param>
 /// <param name="valueFormat">The value format.</param>
 public CommandValue(Func <IExcelContext, Collection <string>, object, bool> func, CellValueKind valueKind, string valueFormat = null)
     : this(func, valueKind, z => valueFormat)
 {
 }
Example #8
0
 public CellsValue(Address r, object value, CellValueKind valueKind = CellValueKind.Value)
     : this(ExcelService.GetAddress(r, 0, 0), value, valueKind)
 {
 }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandValue"/> class.
 /// </summary>
 /// <param name="func">The function.</param>
 /// <param name="valueKind">Kind of the value.</param>
 /// <param name="valueFormat">The value format.</param>
 public CommandValue(Func <bool> func, CellValueKind valueKind, Func <string> valueFormat = null)
     : this((a, b, c) => func(), valueKind, z => valueFormat())
 {
 }
Example #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandValue"/> class.
 /// </summary>
 /// <param name="func">The function.</param>
 /// <param name="valueKind">Kind of the value.</param>
 /// <param name="valueFormat">The value format.</param>
 public CommandValue(Func <bool> func, CellValueKind valueKind, Func <IExcelContext, string> valueFormat = null)
     : this((a, b, c) => func(), valueKind, valueFormat)
 {
 }
Example #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CellValue" /> struct.
 /// </summary>
 /// <param name="fromRow">From row.</param>
 /// <param name="fromCol">From col.</param>
 /// <param name="toRow">To row.</param>
 /// <param name="toCol">To col.</param>
 /// <param name="value">The value.</param>
 /// <param name="valueKind">Kind of the value.</param>
 /// <param name="valueFormat">The value format.</param>
 public CellValue(int fromRow, int fromCol, int toRow, int toCol, object value, CellValueKind valueKind = CellValueKind.Value, string valueFormat = null)
     : this(ExcelService.GetAddress(fromRow, fromCol, toRow, toCol), value, valueKind, valueFormat)
 {
 }
Example #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandValue" /> class.
 /// </summary>
 /// <param name="func">The function.</param>
 /// <param name="valueKind">Kind of the value.</param>
 /// <param name="valuePattern">The value pattern.</param>
 public CommandValue(Func <bool> func, CellValueKind valueKind, string valuePattern = null)
     : this((a, b, c) => func(), valueKind, z => valuePattern)
 {
 }
Example #13
0
 public static object GetCellsValue(this IExcelContext ctx, Address r, int fromRow, int fromCol, int toRow, int toCol, CellValueKind valueKind = CellValueKind.Value) => ctx.GetCellsValue(ExcelService.GetAddress(r, fromRow, fromCol, toRow, toCol), valueKind);
Example #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CellValue" /> struct.
 /// </summary>
 /// <param name="row">The row.</param>
 /// <param name="col">The col.</param>
 /// <param name="value">The value.</param>
 /// <param name="valueKind">Kind of the value.</param>
 /// <param name="valueFormat">The value format.</param>
 public CellValue(int row, int col, object value, CellValueKind valueKind = CellValueKind.Value, string valueFormat = null)
     : this(ExcelService.GetAddress(row, col), value, valueKind, valueFormat)
 {
 }
Example #15
0
 public static object GetCellsValue(this IExcelContext ctx, Address r, int row, int col, CellValueKind valueKind = CellValueKind.Value) => ctx.GetCellsValue(ExcelService.GetAddress(r, row, col), valueKind);
Example #16
0
        public static void CellsValue(this IExcelContext ctx, string cells, object value, CellValueKind valueKind = CellValueKind.Value)
        {
            var range = ((ExcelContext)ctx).WS.Cells[ctx.DecodeAddress(cells)];

            switch (valueKind)
            {
            case CellValueKind.Value: range.Value = value; break;

            case CellValueKind.AutoFilter: range.AutoFilter = value.CastValue <bool>(); break;

            case CellValueKind.AutoFitColumns: range.AutoFitColumns(); break;

            case CellValueKind.Comment: range.Comment.Text = (string)value; break;

            case CellValueKind.CommentMore: break;

            case CellValueKind.ConditionalFormattingMore: break;

            case CellValueKind.Copy:
                var range2 = ((ExcelContext)ctx).WS.Cells[ctx.DecodeAddress((string)value)];
                range.Copy(range2); break;

            case CellValueKind.Formula: range.Formula = (string)value; break;

            case CellValueKind.FormulaR1C1: range.FormulaR1C1 = (string)value; break;

            case CellValueKind.Hyperlink: range.Hyperlink = new Uri((string)value); break;

            case CellValueKind.Merge: range.Merge = value.CastValue <bool>(); break;

            case CellValueKind.RichText: range.RichText.Add((string)value); break;

            case CellValueKind.RichTextClear: range.RichText.Clear(); break;

            case CellValueKind.StyleName: range.StyleName = (string)value; break;

            default: throw new ArgumentOutOfRangeException(nameof(valueKind));
            }
            if (value is DateTime)
            {
                range.Style.Numberformat.Format = DateTimeFormatInfo.CurrentInfo.ShortDatePattern;
            }
        }
Example #17
0
 public static void CellsValue(this IExcelContext ctx, Address r, object value, CellValueKind valueKind = CellValueKind.Value) => ctx.CellsValue(ExcelService.GetAddress(r, 0, 0), value, valueKind);
Example #18
0
 public static void CellsValue(this IExcelContext ctx, int fromRow, int fromCol, int toRow, int toCol, object value, CellValueKind valueKind = CellValueKind.Value) => ctx.CellsValue(ExcelService.GetAddress(fromRow, fromCol, toRow, toCol), value, valueKind);
Example #19
0
 public static void CellsValue(this IExcelContext ctx, int row, int col, object value, CellValueKind valueKind = CellValueKind.Value) => ctx.CellsValue(ExcelService.GetAddress(row, col), value, valueKind);