Ejemplo n.º 1
0
        static private void SetCellValue(ICell cell, SpreadsheetCellData data)
        {
            object value = data.GetValue();

            if (value == null)
            {
                return;
            }
            if (value is string)
            {
                cell.SetCellValue(value as string);
            }
            else
            {
                try
                {
                    double x = Convert.ToDouble(value);
                    cell.SetCellValue(x);
                }
                catch (Exception e)
                {
                    cell.SetCellValue(data.GetValueAsString());
                }
            }
        }
Ejemplo n.º 2
0
        public List <SpreadsheetCellData> AddColumn(int?col = null, List <SpreadsheetCellData> restoreCells = null, SpreadsheetColumnData restoreColumn = null)
        {
            int colIndex = col.HasValue ? col.Value : columnDatas.Count;

            if (colIndex > 0 && colIndex < columnDatas.Count)
            {
                // check for dataTable. Cannot insert between dataTable, so only the first column of dataTable can be inserted
                for (int row = 0; row < rowDatas.Count; ++row)
                {
                    SpreadsheetCellData cell = cells[row][colIndex];
                    if (cell.dataTableData != null)
                    {
                        SpreadsheetRangeData rangeData = valueStore.CreateSpreadsheetRangeDataFromRangeId(cell.dataTableData.rangeId);
                        PointInt?            position  = rangeData.GetPositionOfCell(cell);
                        if (position.Value.X > 0)
                        {
                            throw new Exception("Cannot change part of a data table");
                        }
                    }
                }
            }

            if (restoreColumn == null)
            {
                string newColumnId = columnIdGenerator.NewVariableName();
                columnDatas.Insert(colIndex, new SpreadsheetColumnData(valueStore)
                {
                    id = GetColumnId(newColumnId)
                });
            }
            else
            {
                columnDatas.Insert(colIndex, restoreColumn);
            }

            if (restoreCells == null)
            {
                List <SpreadsheetCellData> newColumn = new List <SpreadsheetCellData>();
                for (int row = 0; row < rowDatas.Count; ++row)
                {
                    string expression            = ResolveRowExpressionForColumn(rowDatas[row].expression, colIndex);
                    SpreadsheetCellData cellData = new SpreadsheetCellData(this.valueStore, GetCellId(row, colIndex), expression);
                    cells[row].Insert(colIndex, cellData);
                    newColumn.Add(cellData);
                }
                return(newColumn);
            }
            else
            {
                for (int row = 0; row < rowDatas.Count; ++row)
                {
                    cells[row].Insert(colIndex, restoreCells[row]);
                }
                return(restoreCells);
            }
        }
Ejemplo n.º 3
0
 public void SetRowExpression(int row, string expression)
 {
     if (rowDatas[row].expression != expression)
     {
         rowDatas[row].expression = expression;
         valueStore.ShouldDispatchPropertyChanged = false;   // don't store changed cells to Undo stack
         for (int col = 0; col < columnDatas.Count; ++col)
         {
             SpreadsheetCellData cellData = cells[row][col];
             cellData.expression = ResolveRowExpressionForColumn(expression, col);
         }
         valueStore.ShouldDispatchPropertyChanged = true;
         valueStore.ResolveValue(rowDatas[row].id);
     }
 }
Ejemplo n.º 4
0
 public void SetColumnExpression(int col, string expression)
 {
     if (columnDatas[col].expression != expression)
     {
         columnDatas[col].expression = expression;
         valueStore.ShouldDispatchPropertyChanged = false;   // don't store changed cells to Undo stack
         for (int row = 0; row < rowDatas.Count; ++row)
         {
             SpreadsheetCellData cellData = cells[row][col];
             cellData.expression = ResolveColumnExpressionForRow(expression, row);
         }
         valueStore.ShouldDispatchPropertyChanged = true;
         valueStore.ResolveValue(columnDatas[col].id);
     }
 }
Ejemplo n.º 5
0
        public List <SpreadsheetCellData> DeleteColumn(int col)
        {
            List <SpreadsheetCellData> removedColumn = new List <SpreadsheetCellData>();

            for (int row = 0; row < rowDatas.Count; ++row)
            {
                SpreadsheetCellData cellData = cells[row][col];
                if (cellData.dataTableData != null)
                {
                    throw new Exception("Cannot change part of a data table");
                }
                removedColumn.Add(cellData);
                cells[row].RemoveAt(col);
            }
            columnDatas.RemoveAt(col);
            return(removedColumn);
        }
Ejemplo n.º 6
0
 // return position of cell if it is part of the range, otherwise return null
 public PointInt?GetPositionOfCell(SpreadsheetCellData cell)
 {
     if (cell.parentId == this.spreadsheet.id)
     {
         PointInt?startPosition = spreadsheet.GetPositionFromCellId(startId);
         PointInt?endPosition   = spreadsheet.GetPositionFromCellId(endId);
         PointInt?cellPosition  = spreadsheet.GetPositionFromCellId(cell.id);
         if (startPosition.HasValue && endPosition.HasValue && cellPosition.HasValue)
         {
             if (cellPosition.Value.X >= startPosition.Value.X && cellPosition.Value.Y >= startPosition.Value.Y &&
                 cellPosition.Value.X <= endPosition.Value.X && cellPosition.Value.Y <= endPosition.Value.Y)
             {
                 return(new PointInt(cellPosition.Value.X - startPosition.Value.X, cellPosition.Value.Y - startPosition.Value.Y));
             }
         }
     }
     return(null);
 }