コード例 #1
0
        public void LoadXML(Stream xmls)
        {
            XmlDocument xmld = new XmlDocument();

            xmld.Load(xmls);

            foreach (XmlNode cells in xmld.GetElementsByTagName("cell"))
            {
                SheetCell curCell = null;
                string    curText = null;
                uint      curBG   = 0xFFFFFFFF;

                foreach (XmlNode cell in cells.ChildNodes)
                {
                    if (cell.Name == "id")
                    {
                        curCell = Name2Cell(cell.InnerText);
                    }
                    else if (cell.Name == "bg")
                    {
                        curBG = Convert.ToUInt32(cell.InnerText, 16);
                    }
                    else if (cell.Name == "text")
                    {
                        curText = cell.InnerText;
                    }
                }

                if (curCell != null)
                {
                    curCell.BGColor = curBG;
                    curCell.Text    = curText;
                }
            }
        }
コード例 #2
0
        private bool ContainsCircularRefRec(SheetCell cell, HashSet <SheetCell> curChain)
        {
            if (curChain.Contains(cell))
            {
                return(true);
            }

            if (Refs.ContainsKey(cell) && Refs[cell].Count > 0)
            {
                curChain.Add(cell);

                foreach (var cellRef in Refs[cell])
                {
                    // create a duplicate HashSet for every new possible walk on the graph of cells.
                    // this is so that cells that reference multiple values that don't contain
                    // crefs wont cause false positives
                    if (ContainsCircularRefRec(cellRef, new HashSet <SheetCell>(curChain)))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
コード例 #3
0
        // check to see if a circ reference occurs if the parent were to add
        // the cell as a dependant
        private bool ContainsCircularRef(SheetCell cell, SheetCell parent)
        {
            var cellChain = new HashSet <SheetCell>();

            cellChain.Add(parent);

            return(ContainsCircularRefRec(cell, cellChain));
        }
コード例 #4
0
        public Spreadsheet(int numRows, int numCols)
        {
            RowCount    = numRows;
            ColumnCount = numCols;

            Cells = new SheetCell[numRows, numCols];
            // initialize each cell in the spreadsheet and handle the PropertyChanged
            // event for each one
            for (int r = 0; r < numRows; r++)
            {
                for (int c = 0; c < numCols; c++)
                {
                    Cells[r, c] = new SheetCell(r, c);
                    Cells[r, c].PropertyChanged += CellChanged;
                }
            }
        }
コード例 #5
0
        private void UpdateRefs(SheetCell cell)
        {
            if (!Refs.ContainsKey(cell))
            {
                return;
            }

            // recompute the values and update Vars dict
            foreach (var refCell in Refs[cell])
            {
                if (refCell.InvalidExp)
                {
                    continue;
                }

                var res = refCell.ETree.Eval();
                Vars[refCell.Name] = res;
                refCell.SetValue(res.ToString());
                CellPropertyChanged(refCell, new PropertyChangedEventArgs("Value"));

                // recursively update ref ref calls etc
                UpdateRefs(refCell);
            }
        }