jt
2021-06-10 5d0d028456874576560552f5a5c4e8b801786f11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using HH.WMS.Utils.ExcelLibrary.BinaryFileFormat;
 
namespace HH.WMS.Utils.ExcelLibrary.SpreadSheet
{
    public class Cell
    {
        private object _value;
        private CellFormat _format;
        private CellStyle _style;
 
        internal SharedResource SharedResource;
 
        public static readonly Cell EmptyCell = new Cell(null);
 
        public Cell(object value)
        {
            _value = value;
            _format = CellFormat.General;
        }
 
        public Cell(object value, string formatString)
        {
            _value = value;
            _format = new CellFormat(CellFormatType.General, formatString);
        }
 
        public Cell(object value, CellFormat format)
        {
            _value = value;
            _format = format;
        }
 
        public override string ToString()
        {
            return this.StringValue;
        }
 
        public bool IsEmpty
        {
            get { return this == EmptyCell; }
        }
 
        public object Value
        {
            get
            {
                return _value;
            }
            set
            {
                if (IsEmpty) throw new Exception("Can not set value to an empty cell.");
                _value = value;
            }
        }
 
        public string StringValue
        {
            get
            {
                if (_value == null)
                {
                    return String.Empty;
                }
                else
                {
                    return _value.ToString();
                }
            }
        }
 
        public DateTime DateTimeValue
        {
            get
            {
                if (_value is double)
                {
                    double days = (double)_value;
                    //Excel counts an extra day for 1900-Feb-29. In reality, 1900 is not a leap year.
                    if (SharedResource.BaseDate == DateTime.Parse("1899-12-31") && days > 59)
                    {
                        days--;
                    }
                    return SharedResource.BaseDate.AddDays(days);
                }
                else if (_value is string)
                {
                    return DateTime.Parse((string)_value);
                }
                else if (_value is DateTime)
                {
                    return (DateTime)_value;
                }
                else
                {
                    throw new Exception("Invalid DateTime Cell.");
                }
            }
            set
            {
                this._value = value;
            }
        }
 
        public string FormatString
        {
            get { return _format.FormatString; }
            set { _format.FormatString = value; }
        }
 
        public CellFormat Format
        {
            get { return _format; }
            set { _format = value; }
        }
 
        public CellStyle Style
        {
            get { return _style; }
            set { _style = value; }
        }
 
        public FONT GetFontForCharacter(UInt16 charIndex)
        {
            return WorksheetDecoder.getFontForCharacter(this, charIndex);
        }
    }
}