Esempio n. 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;
 }
Esempio n. 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));
            }
        }
Esempio n. 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;
 }
Esempio n. 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();
 }
Esempio n. 5
0
 public CellsValue(Address r, int row, int col, object value, CellValueKind valueKind = CellValueKind.Value)
     : this(ExcelService.GetAddress(r, row, col), value, valueKind)
 {
 }
Esempio n. 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)
 {
 }
Esempio n. 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)
 {
 }
Esempio n. 8
0
 public CellsValue(Address r, object value, CellValueKind valueKind = CellValueKind.Value)
     : this(ExcelService.GetAddress(r, 0, 0), value, valueKind)
 {
 }
Esempio n. 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())
 {
 }
Esempio n. 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)
 {
 }
Esempio n. 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)
 {
 }
Esempio n. 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)
 {
 }
Esempio n. 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);
Esempio n. 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)
 {
 }
Esempio n. 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);
Esempio n. 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;
            }
        }
Esempio n. 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);
Esempio n. 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);
Esempio n. 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);