private void findSpreadsheet(Boolean debug_flag = false) { SpreadsheetQuery query = new SpreadsheetQuery(); query.Title = spreadsheetname; if (debug_flag) { Console.WriteLine("Trying to find spreadsheet with name " + spreadsheetname); } SpreadsheetFeed feed = service.Query(query); if (feed.Entries.Count > 0) { spreadsheet = (SpreadsheetEntry)feed.Entries[0]; if (debug_flag) { Console.WriteLine("Found spreadsheet with name " + spreadsheet.Title.Text); } } else { if (debug_flag) { Console.WriteLine("No Spreadsheet with name " + spreadsheetname + " could be found!!!"); } throw new ArgumentNullException("Spreadsheet with name " + spreadsheetname + " not found!!!"); } }
static void Main(string[] args) { Environment.CurrentDirectory = Environment.CurrentDirectory.Substring(0, Environment.CurrentDirectory.LastIndexOf("osum", StringComparison.Ordinal)) + @"\osum\osum\Localisation\"; ss.setUserCredentials("*****@*****.**", "osumisawsum"); SpreadsheetFeed feed = ss.Query(new SpreadsheetQuery()); SpreadsheetEntry sheet = null; //get spreadsheet foreach (var entry in feed.Entries.OfType <SpreadsheetEntry>()) { if (entry.Title.Text == "osu!stream localisation") { sheet = entry; break; } } if (sheet == null) { Console.WriteLine("failed to get spreadsheet"); Console.ReadLine(); } //get worksheet AtomLink link = sheet.Links.FindService(GDataSpreadsheetsNameTable.WorksheetRel, null); WorksheetQuery query = new WorksheetQuery(link.HRef.ToString()); WorksheetFeed wfeed = ss.Query(query); WorksheetEntry worksheet = wfeed.Entries[0] as WorksheetEntry; ProcessWorksheet(worksheet); }
private void GetSpreadsheet(SpreadsheetsService service) { SpreadsheetQuery query = new SpreadsheetQuery(); SpreadsheetFeed feed = service.Query(query); SpreadsheetEntry spreadsheet = null; foreach (SpreadsheetEntry entry in feed.Entries) { if (!entry.Title.Text.Equals("Boardgame Stats")) { continue; } spreadsheet = entry; } if (spreadsheet == null) { MessageBox.Show("You don't appear to have access to the proper spreadsheet."); return; } WorksheetFeed wsFeed = spreadsheet.Worksheets; Games = wsFeed; GetGameDateName(service, spreadsheet, wsFeed); }
public WorksheetEntry GetWorksheetEntry(string name) { /* * var link = entry.Links.FindService(GDataSpreadsheetsNameTable.WorksheetRel, null); * var wsFeed = (WorksheetFeed) client.SpreadsheetService.Query(new WorksheetQuery(link.HRef.ToString()) {Title = name, Exact = true}); * if (wsFeed.Entries.Count == 0) * return null; * * return (WorksheetEntry)wsFeed.Entries [0]; */ SpreadsheetEntry spreadsheet = this.entry as SpreadsheetEntry; WorksheetFeed wsFeed = spreadsheet.Worksheets; // Iterate through each worksheet in the spreadsheet. WorksheetEntry worksheetEntry = null; foreach (WorksheetEntry entry in wsFeed.Entries) { // Retrieve worksheet with the given name. if (entry.Title.Text == name) { worksheetEntry = entry; } } return(worksheetEntry); }
private void GetGameDateName(SpreadsheetsService service, SpreadsheetEntry entry, WorksheetFeed wsFeed) { GamesPlayed = new List <GameEvent>(); List <CellFeed> cellFeeds = DoCellQuery(service, wsFeed, 2, 1, 1); int gameID = 0; for (int i = 0; i < cellFeeds.Count; i++) { CellFeed currentCellFeed = cellFeeds[i]; if (currentCellFeed != null) { foreach (CellEntry cell in currentCellFeed.Entries) { GameEvent newGameEvent = new GameEvent(); string dateTimeString = cell.InputValue; DateTime dateTime = DateTime.Parse(dateTimeString); newGameEvent.Date = dateTime; newGameEvent.Name = wsFeed.Entries[i].Title.Text; newGameEvent.ID = gameID; GamesPlayed.Add(newGameEvent); gameID++; } } } GetPlayers(service, entry, wsFeed); }
public ManagerWindow(string PageName, SpreadsheetsService _service, SpreadsheetEntry _TargetTable, List <DllManager> SharedDll) { Mydlls = SharedDll; service = _service; TargetTable = _TargetTable; this.Text = PageName; CustomLayout(); LoadCombobox(); }
public void LoadSpreadSheet(string spreadSheetId) { SpreadsheetQuery query = new SpreadsheetQuery(); query.Uri = new Uri("https://spreadsheets.google.com/feeds/spreadsheets/private/full/" + spreadSheetId); SpreadsheetFeed feed = service.Query(query); spreadSheetEntry = (SpreadsheetEntry)feed.Entries[0]; }
public static MTSpreadsheet GetSpreadsheet(string title, GoogleParams p) { SpreadsheetsService service = GetService(p); SpreadsheetQuery query = new SpreadsheetQuery(); query.Title = title; SpreadsheetFeed feed = service.Query(query); SpreadsheetEntry spreadsheet = (SpreadsheetEntry)feed.Entries[0]; return(new MTSpreadsheet(spreadsheet, service)); }
private CellFeed GetCellFeed(SpreadsheetsService service, SpreadsheetEntry spEntry) { WorksheetFeed wsFeed = spEntry.Worksheets; WorksheetEntry wsEntry = (WorksheetEntry)wsFeed.Entries[0]; AtomLink wLink = wsEntry.Links.FindService(GDataSpreadsheetsNameTable.CellRel, null); CellQuery cellQuery = new CellQuery(wLink.HRef.ToString()); CellFeed cellFeed = service.Query(cellQuery); return(cellFeed); }
/// <summary> /// Get Worksheets in the given <paramref name="spreadsheet"/>. /// </summary> /// <param name="spreadsheet">The <typeparamref name="Google.GData.Spreadsheets.SpreadsheetEntry" /> from which the worksheets should be returned.</param> /// <returns>Returns a <typeparamref name="Google.GData.Spreadsheets.WorksheetEntry" /> array.</returns> public virtual WorksheetEntry[] GetWorksheets(SpreadsheetEntry spreadsheet) { if (spreadsheet == null) { spreadsheet = GetSpreadsheets()[0]; } var result = new WorksheetEntry[spreadsheet.Worksheets.Entries.Count]; spreadsheet.Worksheets.Entries.CopyTo(result, 0); return(result); }
private List <DatablockDetectionInfo> ParseSpreadsheet(SpreadsheetEntry spreadsheet) { WorksheetFeed wsFeed = spreadsheet.Worksheets; if (wsFeed.Entries.Count == 0) { return(null); } var worksheet = (WorksheetEntry)wsFeed.Entries[0]; if (worksheet.Rows < 2) { return(null); } // Define the URL to request the list feed of the worksheet. AtomLink listFeedLink = worksheet.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null); // Fetch the list feed of the worksheet. var listQuery = new ListQuery(listFeedLink.HRef.ToString()); ListFeed listFeed = sheetsAPI.Service.Query(listQuery); var headers = new List <string>(); spreadsheetRows = listFeed.Entries; nameColumnIndex = -1; var row = (ListEntry)spreadsheetRows[0]; for (int index = 0; index < row.Elements.Count; index++) { ListEntry.Custom element = row.Elements[index]; if (element.LocalName.Equals("name", StringComparison.OrdinalIgnoreCase)) { nameColumnIndex = index; } headers.Add(element.LocalName); } List <DatablockDetectionInfo> datablockTypes = AutoDetectDatablockType(headers); if (datablockTypes == null) { Debug.Log("Unable to auto detect datablock type"); return(null); } return(datablockTypes); }
public async Task ExportToDocumentAsync <TModel>(string path, IReadOnlyList <ResGroupModel <TModel> > groups, IStatusProgress progress, CancellationToken cancellationToken) where TModel : IRowModel { progress.Report(StatusRes.GettingSpreadsheet); SpreadsheetFeed spreadSheets = await Service.GetFeedAsync(new SpreadsheetQuery(path), progress, cancellationToken); SpreadsheetEntry spreadsheet = (SpreadsheetEntry)spreadSheets.Entries.First(); progress.Report(StatusRes.GettingWorksheets); WorksheetFeed worksheetsFeed = await Service.GetFeedAsync(spreadsheet.GetWorkSheetQuery(), progress, cancellationToken); int columsCount = groups.First().Tables.First().Rows.First().DataList.Count; List <KeyValuePair <string, WorksheetEntry> > newWorksheets = groups .Select(g => new KeyValuePair <string, WorksheetEntry>(g.GroupTitle, new WorksheetEntry((uint)(g.Tables.Sum(t => t.Rows.Count + 3) + /*Table name rows*/ g.Tables.Count - 1), (uint)columsCount, g.GroupTitle))) .ToList(); List <WorksheetEntry> worksheets2Rename = worksheetsFeed.Entries.Cast <WorksheetEntry>() .Where(ws => newWorksheets.Any(nws => String.Equals(nws.Key, ws.Title.Text, StringComparison.OrdinalIgnoreCase))) .ToList(); if (worksheets2Rename.Count != 0) { foreach (var worksheetEntry in worksheets2Rename) { worksheetEntry.Title.Text = Guid.NewGuid().ToString("N"); worksheetEntry.BatchData = new GDataBatchEntryData(GDataBatchOperationType.update); } progress.Report(StatusRes.RenamingOldWorksheets); var progresses = progress.CreateParallelProgresses(worksheets2Rename.Count); //Renaming worksheets with matching names. await Task.WhenAll(worksheets2Rename.Zip(progresses, (ws, p) => Service.UpdateItemAsync(ws, p, cancellationToken))); } progress.Report(StatusRes.InsertingNewWorksheets); //Creating new worksheets. var insertingProgresses = progress.CreateParallelProgresses(newWorksheets.Count); var createdWorksheets = await Task.WhenAll(newWorksheets.Zip(insertingProgresses, (kvp, p) => Service.InsertItemAsync(spreadsheet.GetWorkSheetLink(), kvp.Value, p, cancellationToken))); newWorksheets = createdWorksheets.Select(ws => new KeyValuePair <string, WorksheetEntry>(ws.Title.Text, ws)).ToList(); progress.Report(StatusRes.DeletingOldWorksheets); //Clearing of previous worksheets. var deletingProgresses = progress.CreateParallelProgresses(worksheetsFeed.Entries.Count); await Task.WhenAll(worksheetsFeed.Entries.Cast <WorksheetEntry>().Zip(deletingProgresses, (ws, p) => Service.DeleteItemAsync(ws, p, cancellationToken)).ToArray()); progress.Report(StatusRes.PushingCells); var groupWorksheetsJoin = newWorksheets.Join(groups, ws => ws.Key, g => g.GroupTitle, (kvp, group) => new { Group = group, Worksheet = kvp.Value }).ToList(); var groupProgresses = progress.CreateParallelProgresses(groupWorksheetsJoin.Select(j => (double)j.Worksheet.Cols * j.Worksheet.Rows).ToList()); SemaphoreSlim semaphore = new SemaphoreSlim(MaxPushRequestsCount); await Task.WhenAll(groupWorksheetsJoin.Zip(groupProgresses, (j, p) => PushCellsAsync(j.Worksheet, j.Group, semaphore, p, cancellationToken))); }
public SpreadsheetEntry GetSpreadSheet(string spreadsheetName) { // Loop through spreadsheets and find matching spreadsheet SpreadsheetEntry spreadsheet = null; foreach ( var s in _feed.Entries.Where( s => String.Equals(s.Title.Text, spreadsheetName, StringComparison.OrdinalIgnoreCase))) { spreadsheet = (SpreadsheetEntry)s; } return(spreadsheet); }
public List <string> PerformGoogleLookup(string lookupText) { List <string> listNodes = null; string base64str = "TgBhAHQAaABhAG4AcwAkADEA"; SpreadsheetsService service = AuthenticateGoogleUser(base64str); SpreadsheetEntry spEntry = GetSpreadSheetEntry(service); CellFeed cellFeed = GetCellFeed(service, spEntry); listNodes = GetNodeMatches(cellFeed, lookupText); return(listNodes); }
private void selectSpreadsheetButton_Click(object sender, RoutedEventArgs e) { if (spreadsheetsList.SelectedItem == null) { return; } _selectedSpreadsheet = (SpreadsheetEntry)spreadsheetsList.SelectedItem; WorksheetFeed wsFeed = _selectedSpreadsheet.Worksheets; spreadsheetsList.ItemsSource = wsFeed.Entries; selectSpreadsheetButton.IsEnabled = false; useWorksheetButton.IsEnabled = true; useWriterButton.IsEnabled = false; }
private void TakeTable_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { if (MySpreadsheet != null && GoogleTableListView.SelectedItems.Count == 1) { TargetTable = MySpreadsheet[GoogleTableListView.SelectedItems[0].Index]; TakeTable.Text = "Выбрана таблица: " + TargetTable.Title.Text; TakeTable.Enabled = false; ToLog("Таблица выбрана", string.Format("Таблица {0} выбрана из Google аккаунта.", TargetTable.Title.Text)); } else { MessageBox.Show("Выберети только одну таблицу!", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Hand); } }
static WorksheetFeed GetWorksheetFeed(SpreadsheetFeed spreadsheetFeed, string spreadsheetTitle) { SpreadsheetEntry spreadSheetEntry = null; foreach (var entry in spreadsheetFeed.Entries) { if (entry.Title.Text == spreadsheetTitle && entry is SpreadsheetEntry) { spreadSheetEntry = (SpreadsheetEntry)entry; break; } } return(spreadSheetEntry != null ? spreadSheetEntry.Worksheets : null); }
private WorksheetEntry GetWorksheet(SpreadsheetEntry pSpreadsheetEntry) { AtomLink link = tDicingSpreadsheet.Links.FindService(GDataSpreadsheetsNameTable.WorksheetRel, null); string tLink = link.HRef.ToString(); WorksheetQuery tWorksheetQuery = new WorksheetQuery(tLink); tWorksheetQuery.Title = tSheetName; WorksheetFeed wfeed = tService.Query(tWorksheetQuery); WorksheetEntry wentry = wfeed.Entries.FirstOrDefault() as WorksheetEntry; return(wentry); }
/// <summary> /// Get Spreadsheets accessible by the user. Can be filtered with <paramref name="title"/>. /// </summary> /// <param name="title">Filters the accessible spreadsheets. (optional)</param> /// <returns>Returns a <typeparamref name="Google.GData.Spreadsheets.SpreadsheetEntry" /> array.</returns> public virtual SpreadsheetEntry[] GetSpreadsheets(string title = null) { var query = new SpreadsheetQuery(); if (title != null) { query.Title = title; } SpreadsheetFeed feed = this.service.Query(query); // Have to use this "dirty" workaround... var result = new SpreadsheetEntry[feed.Entries.Count]; feed.Entries.CopyTo(result, 0); return(result); }
private List <WorksheetEntry> GetAllWorksheets(SpreadsheetEntry entry) { AtomLink listLink = entry.Links.FindService(GDataSpreadsheetsNameTable.WorksheetRel, AtomLink.ATOM_TYPE); WorksheetQuery query = new WorksheetQuery(listLink.HRef.ToString()); WorksheetFeed feed = spreadsheetService.Query(query); var list = new List <WorksheetEntry>(); foreach (WorksheetEntry worksheet in feed.Entries) { list.Add(worksheet); } return(list); }
public Google2uAccountWorkbook(SpreadsheetEntry in_spreadsheet, Service in_service) { Workbook = in_spreadsheet; WorkbookName = in_spreadsheet.Title.Text; _Service = in_service; foreach ( var link in in_spreadsheet.Links.Where( in_link => in_link.Rel.Equals("alternate", StringComparison.OrdinalIgnoreCase))) { WorkbookUrl = link.HRef.ToString(); break; } Worksheets = new List <Google2uWorksheet>(); }
/// <summary> /// Prints a list of all worksheets in the specified spreadsheet. /// </summary> /// <param name="service">an authenticated SpreadsheetsService object</param> /// <param name="entry">the spreadsheet whose worksheets are to be retrieved</param> private static void PrintAllWorksheets(SpreadsheetsService service, SpreadsheetEntry entry) { AtomLink link = entry.Links.FindService(GDataSpreadsheetsNameTable.WorksheetRel, null); WorksheetQuery query = new WorksheetQuery(link.HRef.ToString()); WorksheetFeed feed = service.Query(query); Console.WriteLine("Worksheets in " + entry.Title.Text + ":"); foreach (WorksheetEntry worksheet in feed.Entries) { allWorksheets.Add(worksheet); Console.WriteLine(" " + worksheet.Title.Text); } Console.WriteLine(); }
private SpreadsheetEntry GetSpreadSheetEntry(SpreadsheetsService service) { SpreadsheetQuery spquery = new SpreadsheetQuery(); SpreadsheetFeed spfeed = service.Query(spquery); SpreadsheetEntry spEntry = null; foreach (SpreadsheetEntry entry in spfeed.Entries) { string fileName = ConfigurationManager.AppSettings["fileNameGoogle"].ToString(); if (entry.Title.Text.Contains(fileName)) { spEntry = entry; break; } } return(spEntry); }
public WorksheetEntry GetWorksheet(SpreadsheetEntry spreadsheet, string worksheetName) { WorksheetEntry worksheet = null; // Loop through worksheets and find matching worksheet if (spreadsheet != null) { WorksheetFeed wsFeed = spreadsheet.Worksheets; foreach ( var w in wsFeed.Entries.Where( w => String.Equals(w.Title.Text, worksheetName, StringComparison.OrdinalIgnoreCase))) { worksheet = (WorksheetEntry)w; } } return(worksheet); }
/*public NameValueCollection getInfo() * { * NameValueCollection parameters = new NameValueCollection(); * WorksheetEntry entry = (WorksheetEntry)m_worksheets["Info"]; * AtomLink listFeedLink = entry.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null); * * ListQuery query = new ListQuery(listFeedLink.HRef.ToString()); * ListFeed feed = m_service.Query(query); * * foreach (ListEntry worksheetRow in feed.Entries) * { * ListEntry.CustomElementCollection elements = worksheetRow.Elements; * parameters.Add(elements[0].Value, elements[1].Value); * } * return parameters; * }*/ private void findSpreadsheet() { SpreadsheetQuery query = new SpreadsheetQuery(); query.Title = m_spreadsheetName; Trace.WriteLine("Trying to find spreadsheet with name " + m_spreadsheetName); SpreadsheetFeed feed = m_service.Query(query); if (feed.Entries.Count > 0) { m_spreadsheetEntry = (SpreadsheetEntry)feed.Entries[0]; Trace.WriteLine("Found spreadsheet with name " + m_spreadsheetEntry.Title.Text); } else { Trace.WriteLine("No Spreadsheet with name " + m_spreadsheetName + " could be found!!!"); throw new ArgumentNullException("Spreadsheet with name " + m_spreadsheetName + " not found!!!"); } }
/// <summary> /// Selects a spreadsheet. /// </summary> /// <param name="entry">The <typeparamref name="Google.GData.Spreadsheets.SpreadsheetEntry" /> which should be selected.</param> /// <exception cref="System.ArgumentNullException"><paramref name="entry"/> is null.</exception> /// <exception cref="System.ArgumentException"><paramref name="entry"/> is no pricelist.</exception> public void SelectSpreadsheet(SpreadsheetEntry entry) { if (entry == null) { throw new ArgumentNullException("entry"); } // Just in case... if (!this.serverRegex.IsMatch(entry.Title.Text)) { throw new ArgumentException(LocalizationManager.GetLocalizedFormatString("IsNoPricelist", entry.Title.Text)); } if (this.currentSpreadsheet != entry) { // Set everything to null so the cache works properly. this.worksheets = null; this.currentWorksheet = null; this.currentSpreadsheet = entry; } }
private void ReadGSFile() { SpreadsheetsService service = new SpreadsheetsService(Constants.googleSheetsAppName); GOAuth2RequestFactory requestFactory = new GOAuth2RequestFactory(null, Constants.googleSheetsAppName, parameters); service.RequestFactory = requestFactory; SpreadsheetQuery query = new SpreadsheetQuery(); SpreadsheetFeed feed = service.Query(query); SpreadsheetEntry spreadsheet = (SpreadsheetEntry)feed.Entries[0]; WorksheetFeed wsFeed = spreadsheet.Worksheets; WorksheetEntry worksheet = (WorksheetEntry)wsFeed.Entries[0]; AtomLink listFeedLink = worksheet.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null); ListQuery listQuery = new ListQuery(listFeedLink.HRef.ToString()); listFeed = service.Query(listQuery); }
public async Task <IReadOnlyList <ResGroupModel <TModel> > > ImportFromDocumentAsync <TModel>(string path, IStatusProgress progress, CancellationToken cancellationToken) where TModel : IRowModel, new() { progress.Report(StatusRes.GettingSpreadsheet); SpreadsheetFeed spreadSheets = await Service.GetFeedAsync(new SpreadsheetQuery(path), progress, cancellationToken); SpreadsheetEntry spreadsheet = (SpreadsheetEntry)spreadSheets.Entries.First(); progress.Report(StatusRes.GettingWorksheets); WorksheetFeed worksheetsFeed = await Service.GetFeedAsync(spreadsheet.GetWorkSheetQuery(), progress, cancellationToken); List <WorksheetEntry> worksheets = worksheetsFeed.Entries.Cast <WorksheetEntry>().ToList(); var progresses = progress.CreateParallelProgresses(worksheets.Select(ws => (double)ws.Cols * ws.Rows).ToList()); progress.Report(StatusRes.GettingWorksheetsData); SemaphoreSlim semaphore = new SemaphoreSlim(MaxPushRequestsCount); var groupTasks = worksheets.Zip(progresses, (entry, p) => GetGroupAsync <TModel>(entry, semaphore, p, cancellationToken)); return((await Task.WhenAll(groupTasks)).ToList()); }
public WorksheetEntry QueryWorksheet(string title) { SpreadsheetQuery query = new SpreadsheetQuery(); query.Title = title; SpreadsheetFeed feed = this.Service.Query(query); if (feed.Entries.Count == 0) { // TODO: There were no spreadsheets, act accordingly. } // TODO: Choose a spreadsheet more intelligently based on your // app's needs. SpreadsheetEntry spreadsheet = (SpreadsheetEntry)feed.Entries[0]; WorksheetFeed wsFeed = spreadsheet.Worksheets; WorksheetEntry worksheet = (WorksheetEntry)wsFeed.Entries[0]; return(worksheet); }
public WorksheetEntry GetWorkSheet(SpreadsheetsService service, string spreadSheetName, string workSheetName) { Init(); if (service == null) { return(null); } SpreadsheetQuery query = new SpreadsheetQuery(); query.Title = spreadSheetName; query.Exact = true; //Iterate over the results var feed = service.Query(query); if (feed.Entries.Count == 0) { Debug.LogError("can't find spreadsheet : " + spreadSheetName); return(null); } SpreadsheetEntry spreadsheet = (SpreadsheetEntry)feed.Entries[0]; WorksheetFeed wsFeed = spreadsheet.Worksheets; WorksheetEntry worksheet = null; for (int i = 0; i < wsFeed.Entries.Count; i++) { if (wsFeed.Entries[i].Title.Text == workSheetName) { worksheet = wsFeed.Entries[i] as WorksheetEntry; break; } } if (worksheet == null) { Debug.LogError("can't find worksheet : " + workSheetName); } return(worksheet); }