public virtual void Download() { // Create spreadsheet downloader Utils.SpreadsheetDownloader Downloader = new Utils.SpreadsheetDownloader(); // Get the spreadsheet title string Title = Downloader.GetPageTitle(SpreadsheetUrl); SpreadsheetTitle = Title.Replace(GOOGLE_SHEETS_TITLE, ""); // Get data from spreadsheet and fill data dictionary var Data = Downloader.DownloadString(SpreadsheetCsvUrl); if (!string.IsNullOrWhiteSpace(Data)) { string[] Headings = new string[0]; foreach (string[] Line in Utils.StringUtils.ParseData(Data, Utils.StringUtils.ParseMethod.CSV)) { if (Line.Length >= 1 && !string.IsNullOrWhiteSpace(Line[0])) { if (Headings.Length == 0) { // Create headings Headings = new string[Line.Length]; for (int i = 0; i < Headings.Length; ++i) { string Key = Line[i].Trim(); Headings[i] = Key; if (!SpreadsheetData.ContainsKey(Key)) { SpreadsheetData.Add(Key, new List <string>()); } else { SpreadsheetData[Key] = new List <string>(); } } } else { // Add data to headings for (int i = 0; i < Headings.Length; ++i) { string Key = Headings[i]; string Value = i < Line.Length ? Line[i].Trim() : string.Empty; SpreadsheetData[Key].Add(Value); } } } } } // Process data Process(); }
public virtual void Download() { // Create spreadsheet downloader Utils.SpreadsheetDownloader Downloader = new Utils.SpreadsheetDownloader(); // Get the spreadsheet title string Title = Downloader.GetPageTitle(SpreadsheetUrl); SpreadsheetTitle = Title.Replace(GOOGLE_SHEETS_TITLE, ""); // Get data from spreadsheet and fill data dictionary var Data = Downloader.DownloadString(SpreadsheetCsvUrl); if(!string.IsNullOrWhiteSpace(Data)) { string[] Headings = new string[0]; foreach(string[] Line in Utils.StringUtils.ParseData(Data, Utils.StringUtils.ParseMethod.CSV)) { if (Line.Length >= 1 && !string.IsNullOrWhiteSpace(Line[0])) { if (Headings.Length == 0) { // Create headings Headings = new string[Line.Length]; for (int i = 0; i < Headings.Length; ++i) { string Key = Line[i].Trim(); Headings[i] = Key; if (!SpreadsheetData.ContainsKey(Key)) { SpreadsheetData.Add(Key, new List<string>()); } else { SpreadsheetData[Key] = new List<string>(); } } } else { // Add data to headings for (int i = 0; i < Headings.Length; ++i) { string Key = Headings[i]; string Value = i < Line.Length ? Line[i].Trim() : string.Empty; SpreadsheetData[Key].Add(Value); } } } } } // Process data Process(); }