예제 #1
0
        public void Remove()
        {
            CellProxy cell = this._wsheet.GetCell(this._row, this._col);

            if (cell != null)
            {
                cell.RemoveFormula();
            }
        }
        public void Remove()
        {
            CellProxy c = _wsheet.GetCell(_row, _col);

            if (c != null)
            {
                c.RemoveFormula();
            }
        }
예제 #3
0
        private object GetValue()
        {
            CellProxy c = this.Worksheet.GetCell(this.Row, this.Column);

            if (c != null)
            {
                if (c.DataType != null)
                {
                    CellValues cellDataType = (CellValues)c.DataType;
                    if (cellDataType == CellValues.Number)
                    {
                        return(c.Value);
                    }
                    if (cellDataType == CellValues.InlineString)
                    {
                        return(c.Value);
                    }
                    else if (cellDataType == CellValues.SharedString)
                    {
                        if (c.Value != null)
                        {
                            return(this.Worksheet.Document.SharedStrings.Get(Convert.ToUInt32(c.Value)));
                        }
                    }
                }
                if (c.StyleIndex != null)
                {
                    CellFormat cf = this.Worksheet.Document.Styles.GetCellFormat(c.StyleIndex.Value);
                    if (this.Worksheet.Document.Styles.IsDateFormat(cf))
                    {
                        if (c.Value != null)
                        {
                            return(DateTime.FromOADate((double)c.Value));
                        }
                    }
                    else
                    {
                        if (c.Value != null)
                        {
                            return(c.Value);
                        }
                    }
                }
                else
                {
                    if (c.Value != null)
                    {
                        return(c.Value);
                    }
                }
            }
            return(null);
        }
예제 #4
0
        private object GetValue()
        {
            CellProxy cell = this.Worksheet.GetCell(this.Row, this.Column);

            if (cell != null)
            {
                if (cell.DataType.HasValue)
                {
                    CellValues values = cell.DataType.Value;
                    switch (values)
                    {
                    case CellValues.Number:
                        return(cell.Value);

                    case CellValues.InlineString:
                        return(cell.Value);
                    }
                    if ((values == CellValues.SharedString) && (cell.Value != null))
                    {
                        return(this.Worksheet.Document.SharedStrings.Get(Convert.ToUInt32(cell.Value)));
                    }
                }
                if (cell.StyleIndex.HasValue)
                {
                    CellFormat cellFormat = this.Worksheet.Document.Styles.GetCellFormat(cell.StyleIndex.Value);
                    if (!this.Worksheet.Document.Styles.IsDateFormat(cellFormat))
                    {
                        if (cell.Value != null)
                        {
                            return(cell.Value);
                        }
                    }
                    else if (cell.Value != null)
                    {
                        return(DateTime.FromOADate((double)cell.Value));
                    }
                }
                else if (cell.Value != null)
                {
                    return(cell.Value);
                }
            }
            return(null);
        }
예제 #5
0
 public virtual void VisitCellStart(CellProxy cell)
 {
 }
예제 #6
0
 public virtual void VisitCellEnd(CellProxy cell)
 {
 }
예제 #7
0
        private void SetValue(object value)
        {
            CellProxy proxy = this.Worksheet.EnsureCell(this.Row, this.Column);
            bool      flag  = false;

            if (proxy.StyleIndex.HasValue)
            {
                CellFormat cellFormat = this.Worksheet.Document.Styles.GetCellFormat(proxy.StyleIndex.Value);
                if (this.Worksheet.Document.Styles.IsDateFormat(cellFormat))
                {
                    flag = true;
                }
            }
            if (value == null)
            {
                proxy.DataType = null;
                proxy.Value    = null;
            }
            else
            {
                Type valueType = value.GetType();
                if (valueType == typeof(DateTime))
                {
                    proxy.DataType = null;
                    if (!flag)
                    {
                        CellFormat cfNew = new CellFormat {
                            ApplyNumberFormat = true,
                            NumberFormatId    = 14
                        };
                        uint?styleIndex = proxy.StyleIndex;
                        uint num        = this.Worksheet.Document.Styles.MergeAndRegisterCellFormat(cfNew, styleIndex.HasValue ? ((UInt32Value)styleIndex.GetValueOrDefault()) : null, false);
                        proxy.StyleIndex = new uint?(num);
                    }
                    proxy.Value = ((DateTime)value).ToOADate();
                }
                else if (ValueChecker.IsNumeric(valueType))
                {
                    if (flag)
                    {
                        CellFormat format4 = new CellFormat {
                            NumberFormatId = 0
                        };
                        uint?nullable6 = proxy.StyleIndex;
                        uint num2      = this.Worksheet.Document.Styles.MergeAndRegisterCellFormat(format4, nullable6.HasValue ? ((UInt32Value)nullable6.GetValueOrDefault()) : null, false);
                        proxy.StyleIndex = new uint?(num2);
                    }
                    proxy.DataType = (CellValues)1;
                    proxy.Value    = value;
                }
                else
                {
                    if (flag)
                    {
                        CellFormat format6 = new CellFormat {
                            NumberFormatId = 0
                        };
                        uint?nullable7 = proxy.StyleIndex;
                        uint num3      = this.Worksheet.Document.Styles.MergeAndRegisterCellFormat(format6, nullable7.HasValue ? ((UInt32Value)nullable7.GetValueOrDefault()) : null, false);
                        proxy.StyleIndex = new uint?(num3);
                    }
                    string valueStr = value.ToString();
                    int    num4     = this.Worksheet.Document.SharedStrings.Put(valueStr);
                    proxy.DataType = (CellValues)3;
                    proxy.Value    = (uint)num4;
                }
            }
        }
예제 #8
0
        private void SetValue(object value)
        {
            CellProxy c             = this.Worksheet.EnsureCell(this.Row, this.Column);
            bool      hasDateFormat = false;

            if (c.StyleIndex != null)
            {
                CellFormat cfCurrent = this.Worksheet.Document.Styles.GetCellFormat(c.StyleIndex.Value);
                if (this.Worksheet.Document.Styles.IsDateFormat(cfCurrent))
                {
                    hasDateFormat = true;
                }
            }

            if (value == null)
            {
                c.DataType = null;
                c.Value    = null;
            }
            else
            {
                Type valueType = value.GetType();
                if (valueType == typeof(DateTime))
                {
                    c.DataType = null;
                    if (!hasDateFormat)
                    {
                        // 14 = generic date format
                        CellFormat cfDate = new CellFormat()
                        {
                            ApplyNumberFormat = true, NumberFormatId = 14
                        };
                        uint cfIdxDate = this.Worksheet.Document.Styles.MergeAndRegisterCellFormat(cfDate, c.StyleIndex, false);
                        c.StyleIndex = cfIdxDate;
                    }
                    DateTime dtValue = (DateTime)value;
                    c.Value = dtValue.ToOADate();
                }
                else if (ValueChecker.IsNumeric(valueType))
                {
                    if (hasDateFormat)
                    {
                        CellFormat cfGeneric = new CellFormat()
                        {
                            NumberFormatId = 0
                        };
                        uint cfIfxGeneric = this.Worksheet.Document.Styles.MergeAndRegisterCellFormat(cfGeneric, c.StyleIndex, false);
                        c.StyleIndex = cfIfxGeneric;
                    }
                    c.DataType = CellValues.Number;
                    c.Value    = value;
                }
                else
                {
                    if (hasDateFormat)
                    {
                        CellFormat cfGeneric = new CellFormat()
                        {
                            NumberFormatId = 0
                        };
                        uint cfIfxGeneric = this.Worksheet.Document.Styles.MergeAndRegisterCellFormat(cfGeneric, c.StyleIndex, false);
                        c.StyleIndex = cfIfxGeneric;
                    }
                    string valueStr     = value.ToString();
                    int    sharedStrIdx = this.Worksheet.Document.SharedStrings.Put(valueStr);
                    c.DataType = CellValues.SharedString;
                    c.Value    = (uint)sharedStrIdx;
                }
            }
        }