public Cell CreateCell(int row, int col, object value, int XFindex)
 {
     XF xf = SharedResource.ExtendedFormats[XFindex];
     CellFormat foramt = SharedResource.CellFormats[xf.FormatIndex];
     Cell cell = new Cell(value, foramt);
     cell.SharedResource = this.SharedResource;
     cell.Style = CreateStyleFromXF(xf);
     this[row, col] = cell;
     return cell;
 }
 private static CellValue EncodeCell(Cell cell, SharedResource sharedResource)
 {
     object value = cell.Value;
     if (value is int || value is short || value is uint || value is byte)
     {
         RK rk = new RK();
         rk.Value = (uint)(Convert.ToInt32(value) << 2 | 2);
         return rk;
     }
     else if (value is decimal)
     {
         if (Math.Abs((decimal)value) <= (decimal)5368709.11)
         {
             RK rk = new RK();
             rk.Value = (uint)((int)((decimal)value * 100) << 2 | 3); // integer and mul
             return rk;
         }
         else
         {
             NUMBER number = new NUMBER();
             number.Value = (double)(decimal)value;
             return number;
         }
     }
     else if (value is double)
     {
         //RK rk = new RK();
         //Int64 data = BitConverter.DoubleToInt64Bits((double)value);
         //rk.Value = (uint)(data >> 32) & 0xFFFFFFFC;
         //return rk;
         NUMBER number = new NUMBER();
         number.Value = (double)value;
         return number;
     }
     else if (value is string)
     {
         LABELSST label = new LABELSST();
         label.SSTIndex = sharedResource.GetSSTIndex((string)value);
         return label;
     }
     else if (value is DateTime)
     {
         NUMBER number = new NUMBER();
         number.Value = sharedResource.EncodeDateTime((DateTime)value);
         return number;
     }
     else if (value is bool)
     {
         BOOLERR boolerr = new BOOLERR();
         boolerr.ValueType = 0;
         boolerr.Value = Convert.ToByte((bool)value);
         return boolerr;
     }
     else if (value is ErrorCode)
     {
         BOOLERR boolerr = new BOOLERR();
         boolerr.ValueType = 1;
         boolerr.Value = ((ErrorCode)value).Code;
         return boolerr;
     }
     else
     {
         throw new Exception("Invalid cell value.");
     }
 }
Exemple #3
0
 public void SetCell(int colIndex, Cell cell)
 {
     FirstColIndex = Math.Min(FirstColIndex, colIndex);
     LastColIndex = Math.Max(LastColIndex, colIndex);
     Cells[colIndex] = cell;
 }
        /*
         * Sunil Shenoi, 8-25-2008
         * 
         * Assuming cell has a valid string vlaue, find the font record for a given characterIndex
         * into the stringValue of the cell
         */
        public static FONT getFontForCharacter(Cell cell, UInt16 charIndex)
        {
            FONT f = null;

            int index = cell.Style.RichTextFormat.CharIndexes.BinarySearch(charIndex);
            List<UInt16> fontIndexList = cell.Style.RichTextFormat.FontIndexes;
            
            if (index >= 0)
            {
                // found the object, return the font record
                f = getFontRecord(cell.SharedResource, fontIndexList[index]);
                //Console.WriteLine("for charIndex={0}, fontIndex={1})", charIndex, fontIndexList[index]);
                //Console.WriteLine("Object: {0} found at [{1}]", o, index);
            }
            else
            {
                // would have been inserted before the returned value, so insert just before it
                if (~index == 0)
                {
                    //f = getFontRecord(sheet,fontIndexList[0]);
                    //Console.WriteLine("for charIndex={0}, fontIndex=CELL", charIndex);
                }
                else
                {
                    f = getFontRecord(cell.SharedResource, fontIndexList[(~index) - 1]);
                    //Console.WriteLine("for charIndex={0}, fontIndex={1})", charIndex, fontIndexList[(~index) - 1]);
                }
                //Console.WriteLine("Object: {0} not found. "
                //   + "Next larger object found at [{1}].", o, ~index);
            }

            return f;
        }