Esempio n. 1
0
File: Form1.cs Progetto: 3505VFD/VFD
        public void ProcessSpreadsheetLoad(Byte[] b, string[] s)
        {
            MemoryStream stream = new MemoryStream(b);
            StreamReader reader = new StreamReader(stream);
            Dictionary <string, string> spreadsheetData = new Dictionary <string, string>();

            string[] str;
            // Begin reading the data stream
            using (reader)
            {
                try
                {
                    // Get the json data for the whole spreadsheet file
                    string jsonString = reader.ReadLine();
                    //int begin = jsonString.IndexOf('0');
                    int      end    = jsonString.IndexOf('}');
                    string   actual = jsonString.Substring(2, end);
                    string[] bits   = actual.Split(',');
                    string[] cells;
                    string   cellName;
                    string   contents;
                    foreach (string cell in bits)
                    {
                        cells = cell.Split(':');

                        cellName = cells[0].Replace('\"', ' ').Trim();
                        contents = cells[1].Replace('\"', ' ').Trim();

                        ss.SetContentsOfCell(cellName, contents);
                    }
                }
                catch (Exception)
                {}
            }

            // Iterate through the deserialized JsonString data and
            // set the data appropriately within the representation of the
            // spreadsheet within the form.
            foreach (string cell in spreadsheetData.Keys)
            {
                if (cell.Equals("version"))
                {
                    ss.SetVersion(spreadsheetData[cell]);
                }
                else
                {
                    ss.SetContentsOfCell(cell, spreadsheetData[cell]);
                }
            }
        }