Exemplo n.º 1
0
 private static void InsertCell(XlRowData rowData, XlCell cell, int intendedIndex)
 {
     intendedIndex--;                           //indexing starts at 1, not 0
     if (rowData._cells.Count == intendedIndex) //it's the right place, just do an Add
     {
         rowData._cells.Add(cell);
     }
     else if (rowData._cells.Count > intendedIndex)
     {
         rowData._cells[intendedIndex] = cell;  //this may overwrite a cell in theory
     }
     else
     {
         //we need to skip ahead by adding a bunch of nulls
         while (rowData._cells.Count < intendedIndex)
         {
             rowData._cells.Add(dummy);
         }
         rowData._cells.Add(cell); //that'll do it!
     }
 }
Exemplo n.º 2
0
        private static void AddCell(XlRowData rowData, XlSharedStringsTable stringTable, Cell cell, int intendedIndex)
        {
            uint   style     = cell.StyleIndex ?? 0U;
            string cellValue = cell.CellValue != null ? cell.CellValue.InnerText : "";
            string datatype  = null;

            if (cell.DataType == null)
            {
                datatype = CellValues.Number.ToString();
            }
            else if (cell.DataType.Value == CellValues.SharedString)
            {
                datatype = CellValues.String.ToString();
                int stringIndex = Int32.Parse(cellValue);
                cellValue = stringTable[stringIndex];
            }
            else
            {
                datatype = cell.DataType.Value.ToString();
            }
            XlCell newCell = new XlCell(style, typeof(string), cellValue, datatype);

            InsertCell(rowData, newCell, intendedIndex);
        }
Exemplo n.º 3
0
        public void AddRow(int index, Dictionary <string, string> values)
        {
            XlRowData row = new XlRowData();
            Dictionary <string, string> tmp = new Dictionary <string, string>(); //this stinks but handles the case insensitive issue

            foreach (KeyValuePair <string, string> item in values)
            {
                tmp[item.Key.ToLowerInvariant()] = item.Value;
            }
            foreach (XlColumn column in Schema.Columns)
            {
                XlCell cell;
                if (column.CellValue != null)
                {
                    cell = new XlCell(0U, column.Type, tmp[column.CellValue.ToLowerInvariant()]); //the column names are not lower case internally so the output gets the right casing on save.
                }
                else
                {
                    cell = new XlCell(0U, column.Type, "");
                }
                row.AddCell(cell);
            }
            Rows.AddRow(row, index);
        }