Ejemplo n.º 1
0
        public Cell GetCell(ExcelAddress.Cell address)
        {
            Dictionary <uint, Cell> rows;

            if (this.cells.TryGetValue(address.ColumnIndex, out rows))
            {
                Cell cell;
                if (rows.TryGetValue(address.RowIndex, out cell))
                {
                    return(cell);
                }
            }

            throw new KeyNotFoundException(String.Format("No cell exists at {0}", address.CellReferenceString));
        }
Ejemplo n.º 2
0
        public void WriteValue(ExcelAddress.Cell address, object value)
        {
            var cell = this.GetCell(address);

            if (value == null)
            {
                cell.CellValue = new CellValue(null);
                return;
            }

            var typ = value.GetType();

            if (typ == typeof(string))
            {
                var v     = (string)value;
                var index = this.Workbook.InsertSharedStringItem(v);
                cell.CellValue = new CellValue(index.ToString(CultureInfo.InvariantCulture));
                cell.DataType  = new EnumValue <CellValues>(CellValues.SharedString);
                return;
            }

            if (typ == typeof(DateTime))
            {
                var    dt      = (DateTime)value;
                string dtValue = dt.ToOADate().ToString(CultureInfo.InvariantCulture);
                cell.CellValue = new CellValue(dtValue);
                cell.DataType  = new EnumValue <CellValues>(CellValues.Number);

                return;
            }

            if (ExcelWorkbook.NumericTypes.Contains(typ))
            {
                cell.CellValue = new CellValue(value.ToString());
                cell.DataType  = new EnumValue <CellValues>(CellValues.Number);
                return;
            }

            throw new InvalidOperationException(string.Format("the type {0} is not currently supported if it is an array values should be boxed to type object[][]", typ.FullName));
        }