public GDataAPI(NameValueCollection parameters)
        {
            try
            {
                SpreadsheetsService service = new SpreadsheetsService("post2spreadsheet");
                service.setUserCredentials(cardeira.Properties.Settings.Default.gUserName, cardeira.Properties.Settings.Default.gPassword);

                Google.GData.Spreadsheets.SpreadsheetQuery query = new Google.GData.Spreadsheets.SpreadsheetQuery();

                SpreadsheetFeed feed = service.Query(query);
                SpreadsheetEntry entry = null;
                foreach (SpreadsheetEntry e in feed.Entries)
                {
                    entry = e;
                    logger.Debug("Spreadsheet: {0}", entry.Title.Text);
                    if (entry.Title.Text == cardeira.Properties.Settings.Default.spreadsheetkey)
                        break;
                }
                if (entry != null)
                    InsertRow(service, (WorksheetEntry)entry.Worksheets.Entries[0], parameters);
            }
            catch (Exception e)
            {
                logger.ErrorException("error writing to spreadsheet", e);
            }
        }
        private IEnumerable <WorksheetEntry> GetWorksheetEntres(SpreadsheetsService service = null)
        {
            if (service == null)
            {
                service = new SpreadsheetsService(applicationName);
            }
            service.setUserCredentials(userName, password);

            // Instantiate a SpreadsheetQuery object to retrieve spreadsheets.
            SpreadsheetQuery query = new SpreadsheetQuery();

            query.Title = spreadsheetName;
            // Make a request to the API and get all spreadsheets.
            SpreadsheetFeed feed = service.Query(query);

            if (feed.Entries.Count == 0)
            {
                return(null);
            }
            var woorkSheets =
                feed.Entries.OfType <SpreadsheetEntry>()
                .ToList();

            return
                (woorkSheets
                 .SelectMany(entry => entry.Worksheets.Entries.OfType <WorksheetEntry>()));
        }
        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            listView2.Clear();
            if (listView1.SelectedItems.Count == 0)
            {
                return;
            }

            var documentTitle = this.listView1.SelectedItems[0].SubItems[0].Text;

            var query = new SpreadsheetQuery();
            query.Title = documentTitle;

            //looking for a exact worksheet of the given selected title. Returns 1 match.
            var selectedSpreadsheet = (SpreadsheetEntry)App.Service.Query(query).Entries[0];

            //retrieve all worksheets available in the selected spreadsheet.
            var allWorksheetsFeed = selectedSpreadsheet.Worksheets;

            foreach (var worksheet in allWorksheetsFeed.Entries)
            {
                var listItem = new ListViewItem(worksheet.Title.Text){Tag = worksheet};
                this.listView2.Items.Add(listItem);
            }
        }
        public SpreadSheet()
        {
            service = new SpreadsheetsService("stock-market");
            service.setUserCredentials("shurai", "$gva99void!");

            SpreadsheetQuery query = new SpreadsheetQuery();
            SpreadsheetFeed feed = service.Query(query);

            SpreadsheetEntry ssentry = (SpreadsheetEntry)feed.Entries[0];

            AtomLink sslink = ssentry.Links.FindService(GDataSpreadsheetsNameTable.WorksheetRel, null);
            WorksheetQuery wkquery = new WorksheetQuery(sslink.HRef.ToString());
            WorksheetFeed wkfeed = service.Query(wkquery);
            WorksheetEntry wkentry = (WorksheetEntry)wkfeed.Entries[0];

            listFeedLink = wkentry.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null);
            listQuery = new ListQuery(listFeedLink.HRef.ToString());
            listFeed = service.Query(listQuery);

            Console.WriteLine("Worksheet has {0} rows: ", listFeed.Entries.Count);
            foreach (ListEntry worksheetRow in listFeed.Entries)
            {
                ListEntry.CustomElementCollection elements = worksheetRow.Elements;
                foreach (ListEntry.Custom element in elements)
                {
                    Console.Write(element.Value + "\t");
                }
                Console.WriteLine();
            }
        }
        public string GetTotalMoney()
        {
            SpreadsheetQuery query = new SpreadsheetQuery();

            // Make a request to the API and get all spreadsheets.
            SpreadsheetFeed feed = _spreadsheetService.Query(query);

            var _spreadsheet = feed.Entries.FirstOrDefault(s => s.Title.Text == "RTBS 체크카드 사용 내역서");
            var spreadsheet = _spreadsheet as SpreadsheetEntry;
            if (spreadsheet != null)
            {
                var worksheet = spreadsheet.Worksheets.Entries.FirstOrDefault() as WorksheetEntry;
                if (worksheet != null){
                     CellQuery cellQuery = new CellQuery(worksheet.CellFeedLink);
                     cellQuery.MinimumRow = 2;
                     cellQuery.MinimumColumn = 4;
                     cellQuery.MaximumColumn = 4;
                     CellFeed cellFeed = _spreadsheetService.Query(cellQuery);

                     // Iterate through each cell, printing its value.
                     foreach (CellEntry cell in cellFeed.Entries)
                     {
                         if (cell.InputValue.Contains("=SUM"))
                         {
                             return cell.Value;
                         }
                     }
                }
            }
            return "";
        }
Beispiel #6
0
        public SpreadsheetsService GetSpreadsheetService()
        {
            if (_service == null)
            {
                DoAuth();

                // Instantiate a SpreadsheetQuery object to retrieve spreadsheets.
                SpreadsheetQuery query = new SpreadsheetQuery();
                query.Title = "Test Monkey";

                // Make a request to the API and get all spreadsheets.
                SpreadsheetFeed feed = null;
                try
                {
                    feed = _service.Query(query);
                }
                catch (Exception ex)
                {
                }

                // Iterate through all of the spreadsheets returned
                var spreadsheet = feed.Entries.Single();

                // Make a request to the API to fetch information about all
                // worksheets in the spreadsheet.
                var wsFeed = ((SpreadsheetEntry)spreadsheet).Worksheets;

                _toProcessSheet = ((WorksheetFeed)wsFeed).Entries.Single(x => x.Title.Text.Equals("To Process"));
                _processedSheet = ((WorksheetFeed)wsFeed).Entries.Single(x => x.Title.Text.Equals("Processed"));
                _everythingSheet = ((WorksheetFeed)wsFeed).Entries.Single(x => x.Title.Text.Equals("Everything"));
            }

            return _service;
        }
        public ActionResult AllCells()
        {
            SpreadsheetsService service;

            service = new SpreadsheetsService("DevFestEvent");
            service.setUserCredentials(
                ConfigurationManager.AppSettings["GoogleUser"],
                 ConfigurationManager.AppSettings["GoogleUserPassword"]);
            SpreadsheetQuery q = new SpreadsheetQuery(App.SheetFeedData);
            var feed = service.Query(q);
            AtomLink l = feed.Entries.First().Links.FindService(GDataSpreadsheetsNameTable.WorksheetRel, null);
            WorksheetQuery query = new WorksheetQuery(l.HRef.ToString());
            WorksheetFeed f = service.Query(query);

            foreach (var item in f.Entries)
            {
                AtomLink cellFeedLink = item.Links.FindService(GDataSpreadsheetsNameTable.CellRel, null);
                var cellfeedlink = cellFeedLink.HRef.ToString();

                CellQuery cquery = new CellQuery(cellfeedlink);
                CellFeed cfeed = service.Query(cquery);

                Console.WriteLine("Cells in this worksheet:");
                uint rownum = 2;

                foreach (CellEntry curCell in cfeed.Entries)
                {
                    rownum = curCell.Cell.Row;
                }
            }
            return View(f);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //////////////////////////////////////////////////////////////////////////////
            //// STEP 5: Make an OAuth authorized request to Google
            //////////////////////////////////////////////////////////////////////////////

            // Initialize the variables needed to make the request
            GOAuth2RequestFactory requestFactory =
                new GOAuth2RequestFactory(null, "TourTracking", parameters);
            SpreadsheetsService service = new SpreadsheetsService("TourTracking");
            service.RequestFactory = requestFactory;

            // Instantiate a SpreadsheetQuery object to retrieve spreadsheets.
            SpreadsheetQuery query = new SpreadsheetQuery();

            // Make a request to the API and get all spreadsheets.
            SpreadsheetFeed feed = service.Query(query);

            // Iterate through all of the spreadsheets returned
            foreach (SpreadsheetEntry entry in feed.Entries)
            {
                // Print the title of this spreadsheet to the screen
                MessageBox.Show(entry.Title.Text);
            }
        }
Beispiel #9
0
    public string GetSpreadsheets(Hashtable State, RadComboBox Spreadsheets)
    {
        try
        {
            SpreadsheetsService service = new SpreadsheetsService(State["SelectedApp"].ToString());

            GOAuthRequestFactory requestFactory = new GOAuthRequestFactory("wise", "MobiFlex");
            requestFactory.ConsumerKey = ConfigurationManager.AppSettings["GoogleAppsKey"];
            requestFactory.ConsumerSecret = ConfigurationManager.AppSettings["GoogleAppsSecret"];
            service.RequestFactory = requestFactory;
            //get all spreadsheets
            Google.GData.Spreadsheets.SpreadsheetQuery query = new Google.GData.Spreadsheets.SpreadsheetQuery();
            query.OAuthRequestorId = State["CustomerEmail"].ToString();
            query.Uri = new Uri("https://spreadsheets.google.com/feeds/spreadsheets/private/full?xoauth_requestor_id=" + State["CustomerEmail"].ToString());

            SpreadsheetFeed feed = service.Query(query);

            Spreadsheets.Items.Clear();
            Spreadsheets.Items.Add(new RadComboBoxItem("Select Spreadsheet ->", "->"));
            foreach (SpreadsheetEntry entry in feed.Entries)
            {
                string spreadsheet_name = entry.Title.Text;
                Spreadsheets.Items.Add(new RadComboBoxItem(spreadsheet_name, spreadsheet_name));
            }
            return "OK";
        }
        catch (Exception ex)
        {
            Util util = new Util();
            util.LogError(State, ex);
            return ex.Message;
        }
    }
Beispiel #10
0
    public WorksheetEntry GetWorkSheet(SpreadsheetsService service, string spreadSheetName, string workSheetName)
    {
        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;
    }
        private void WorksheetListForm_Load(object sender, EventArgs e)
        {
            //Check if user/pass are null. If the are null, show the login form.

            if (string.IsNullOrEmpty(App.CurrentUser) ||
                string.IsNullOrEmpty(App.CurrentPassword))
            {
                var loginForm = new LoginForm();
                loginForm.Show();
                this.Close();
                return;
            }

            // Instantiate a SpreadsheetQuery object to retrieve spreadsheets.
            SpreadsheetQuery query = new SpreadsheetQuery();

            // Make a request to the API and get all spreadsheets.
            SpreadsheetFeed feed = App.Service.Query(query);

            if (feed.Entries.Count == 0)
            {
                MessageBox.Show("There are no spreadsheets created by this user.", "Google Spreadsheets API", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }

            //iterate over each worksheet found and fill the list view with title, author and link
            foreach (var entry in feed.Entries)
            {
                ListViewItem item = new ListViewItem(new string[]{entry.Title.Text,entry.Authors[0].Name, entry.AlternateUri.Content});
                this.listView1.Items.Add(item);
            }
        }
Beispiel #12
0
        public void DoWorkbookQuery(object in_instance)
        {
            var instance = in_instance as Google2uData;

            if (instance == null || InstanceData.Service == null)
            {
                return;
            }

            try
            {
                instance.AccountWorkbooks.Clear();
                var spreadsheetQuery = new Google.GData.Spreadsheets.SpreadsheetQuery();
                var spreadsheetFeed  = InstanceData.Service.Query(spreadsheetQuery);

                foreach (var entry in spreadsheetFeed.Entries)
                {
                    var workbook = new Google2uAccountWorkbook(entry as SpreadsheetEntry, instance.Service);

                    instance.AccountWorkbooks.Add(workbook);
                }
            }
            catch (Exception)
            {
                if (!instance.Commands.Contains(GFCommand.DoLogout))
                {
                    instance.Commands.Add(GFCommand.DoLogout);
                }

                PushNotification("There is a problem with your credentials. Clear the credentials and Re-Authorize G2U");
                //instance.Messages.Add(new G2GUIMessage(GFGUIMessageType.InvalidLogin, ex.Message));
            }

            instance.Commands.Remove(GFCommand.WaitForRetrievingWorkbooks);
        }
        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];
        }
Beispiel #14
0
 /// <summary>
 /// New Method To get Worksheet
 /// </summary>
 /// <returns></returns>
 public WorksheetEntry GetWorksheet(OAuth2Parameters parameters, string IntegrationName, string SpreadSheetURI, SpreadsheetsService service)
 {
     SpreadsheetQuery query = new SpreadsheetQuery(SpreadSheetURI);
     SpreadsheetFeed feed = service.Query(query);
     SpreadsheetEntry spreadsheet = (SpreadsheetEntry)feed.Entries[0];
     WorksheetFeed wsFeed = spreadsheet.Worksheets;
     WorksheetEntry worksheet = (WorksheetEntry)wsFeed.Entries[0];
     return worksheet;
 }
        public IEnumerable<SpreadsheetEntry> GetAllSpreadsheets()
        {
            var query = new SpreadsheetQuery();

            SpreadsheetFeed feed = _service.Query( query );

            var spreadsheets = feed.Entries.Cast<SpreadsheetEntry>().ToList();

            return spreadsheets;
        }
 private void DownloadGoogleSheets()
 {
     SpreadsheetQuery query = new SpreadsheetQuery();
     //query.Uri = new Uri("https://docs.google.com/spreadsheets/d/1mF15NG_33xio52M4z5pw_byuOyTlg0XxkEvuGOtkXsM");
     SpreadsheetFeed feed = myService.Query(query);
     Debug.Log("Spreadsheet: ");
     foreach(SpreadsheetEntry entry in feed.Entries)
     {
         Debug.Log(entry.Title.Text);
     }
 }
        public StatusReporter()
        {
            this.service = new SpreadsheetsService("Seeker");
            this.service.setUserCredentials(username, password);

            XmlTextReader reader = new XmlTextReader(@"\\cob-hds-1\compression\QC\QCing\otherFiles\SpreadSheetDictionary.xml");

            this.spreadsheets = new Dictionary<string, string>();
            string key = "";
            string value = "";
            while (reader.Read())
            {
                switch (reader.NodeType)
                {

                    case XmlNodeType.Text:// Display text
                        Console.Write(reader.Name);

                        key = reader.Value;
                        while (reader.Read())
                        {
                            if (reader.NodeType == XmlNodeType.Text)
                            {
                                value = reader.Value;
                                break;
                            }
                        }
                        if (value != "")
                        {
                            if (!this.spreadsheets.ContainsKey(key))
                            {
                                this.spreadsheets.Add(key, value);
                            }
                        }
                        break;
                }
            }

            SpreadsheetQuery query = new SpreadsheetQuery();
            this.allSheets = this.service.Query(query);

            for (int i = 0; i < allSheets.Entries.Count; i++)
            {
                if (this.allSheets.Entries[i].AlternateUri.Content.Contains("0AnSESHA7JsTFdFFBNjZ1U3JzdEFXdlZOa0dhQXJNMEE"))
                {
                    this.ReportSpreadSheet = (SpreadsheetEntry)allSheets.Entries[i];
                }
                if (this.allSheets.Entries[i].AlternateUri.Content.Contains("0AnSESHA7JsTFdDBGUWtqRVJVbEFFYVlaUmZnRTBaVWc"))
                {
                    this.failSheet = (SpreadsheetEntry)allSheets.Entries[i];
                }
            }
        }
        public IEnumerable<Word> GetWords()
        {
            if (Enabled)
            {
                SpreadsheetsService GoogleService = new SpreadsheetsService("LanguageBooster");

                // FIX ME: Remove credentials from code.
                GoogleService.setUserCredentials("xxx", "xxx");

                SpreadsheetQuery SpreadsheetsQuery = new SpreadsheetQuery();
                SpreadsheetFeed Spreadsheets = GoogleService.Query(SpreadsheetsQuery);

                // Get list of spreadsheets
                foreach (SpreadsheetEntry WordsSheet in Spreadsheets.Entries)
                {
                    System.Diagnostics.Trace.WriteLine(WordsSheet.Title.Text);

                    System.Diagnostics.Trace.WriteLine(WordsSheet.Title.Text);

                    // Get list of worksheets from spreadsgett
                    WorksheetFeed Worksheets = WordsSheet.Worksheets;

                    WorksheetEntry CurrentWorksheet = null;
                    foreach (WorksheetEntry Worksheet in Worksheets.Entries)
                    {
                        CurrentWorksheet = Worksheet;
                        break;
                    }

                    AtomLink CellsLink = CurrentWorksheet.Links.FindService(GDataSpreadsheetsNameTable.CellRel, null);
                    CellQuery CellsQuery = new Google.GData.Spreadsheets.CellQuery(CellsLink.HRef.ToString());
                    CellFeed Cells = GoogleService.Query(CellsQuery);

                    Word word = null;
                    // Load actual table data
                    foreach (CellEntry CurrentCell in Cells.Entries)
                    {
                        if (CurrentCell.Column == 1)
                        {
                            word = new Word();
                            word.Question = CurrentCell.Value;
                        }

                        if (CurrentCell.Column == 2)
                        {
                            word.Answer = CurrentCell.Value;
                            System.Diagnostics.Trace.WriteLine(word.Question + " - " + word.Answer);
                            yield return word;
                        }
                    }
                }
            }
        }
Beispiel #19
0
        /// <summary>
        /// Prints a list of all the user's spreadsheets, and the
        /// list of worksheets that each spreadsheet contains.
        /// </summary>
        /// <param name="service">an authenticated SpreadsheetsService object</param>
        private static void PrintAllSpreadsheetsAndWorksheets(SpreadsheetsService service)
        {
            SpreadsheetQuery query = new SpreadsheetQuery();
            SpreadsheetFeed feed = service.Query(query);

            Console.WriteLine("Your spreadsheets:");
            foreach (SpreadsheetEntry entry in feed.Entries)
            {
                Console.WriteLine("Spreadsheet: {0}", entry.Title.Text);
                PrintAllWorksheets(service, entry);
            }
        }
Beispiel #20
0
        public ListFeed GetListFeedForSpreadsheet(string spreadsheetName)
        {
            SpreadsheetQuery query = new SpreadsheetQuery();
            query.Title = spreadsheetName;
            SpreadsheetFeed feed = _service.Query(query);

            if (feed.Entries.Count != 1)
                throw new Exception("Did not find exactly 1 shiftmylist datasource.");

            WorksheetEntry timelineWorksheet = GetWorksheet(feed, "Data");
            var listFeed = GetListFeed(timelineWorksheet);
            return listFeed;
        }
        //
        // GET: /Spreadsheet/
        public ActionResult Index()
        {
            SpreadsheetsService service;

            service = new SpreadsheetsService("Spreadsheet-GData-Sample-App");
            service.setUserCredentials(
                ConfigurationManager.AppSettings["GoogleUser"],
                 ConfigurationManager.AppSettings["GoogleUserPassword"]);

            SpreadsheetQuery query = new SpreadsheetQuery();
            var feed = service.Query(query);

            return View(feed);
        }
Beispiel #22
0
        private void ConnectTable()
        {
            // Instantiate a SpreadsheetQuery object to retrieve spreadsheets.
            SpreadsheetQuery query = new SpreadsheetQuery();

            // Make a request to the API and get all spreadsheets.
            SpreadsheetFeed feed = service.Query(query);
            if (feed.Entries.Count == 0) {
                return;
            }

            SpreadsheetEntry spreadsheet = (SpreadsheetEntry)feed.Entries [0];
            WorksheetFeed wsFeed = spreadsheet.Worksheets;
            worksheet = (WorksheetEntry)wsFeed.Entries [0];
        }
Beispiel #23
0
        private WorksheetEntry searchForSpreadsheet(string sheetName)
        {
            Google.GData.Spreadsheets.SpreadsheetQuery query = new Google.GData.Spreadsheets.SpreadsheetQuery();

            SpreadsheetFeed feed = service.Query(query);

            foreach (SpreadsheetEntry entry in feed.Entries)
            {
                if (entry.Title.Text == sheetName)
                {
                    return((WorksheetEntry)entry.Worksheets.Entries[0]);
                }
            }

            return(null);
        }
        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;
        }
Beispiel #25
0
        public string getSpreadsheetURL(string sheetName)
        {
            DocumentsService docService = new DocumentsService(this.googleAppName);

            docService.RequestFactory = GoogleOauthAccess.getRequestFactory(this.googleAppName, this.parameters);

            Google.GData.Spreadsheets.SpreadsheetQuery query = new Google.GData.Spreadsheets.SpreadsheetQuery();

            DocumentsListQuery docQuery = new DocumentsListQuery();

            docQuery.Title = sheetName;

            DocumentsFeed feed  = docService.Query(docQuery);
            DocumentEntry entry = (DocumentEntry)feed.Entries[0];

            return("https://docs.google.com/spreadsheet/ccc?key=" + entry.ResourceId.Replace("spreadsheet:", ""));
        }
        //////////////////////////////////////////////////////////////////////
        /// <summary>runs an authentication test</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void GoogleAuthenticationTest()
        {
            Tracing.TraceMsg("Entering Spreadsheet AuthenticationTest");

            SpreadsheetQuery query = new SpreadsheetQuery();
            Service service = new SpreadsheetsService(this.ApplicationName);
            if (this.userName != null)
            {
                service.Credentials = new GDataCredentials(this.userName, this.passWord);
            }
            service.RequestFactory = this.factory; 

            SpreadsheetFeed feed = service.Query(query) as SpreadsheetFeed;

            ObjectModelHelper.DumpAtomObject(feed,CreateDumpFileName("AuthenticationTest")); 
                service.Credentials = null; 
        }
Beispiel #27
0
        //finds a spreadsheet by name, or null if not found.
        public static SpreadsheetEntry findSpreadsheetByName(string sheetName, SpreadsheetsService service)
        {
            SpreadsheetQuery query = new SpreadsheetQuery();

            // Make a request to the API and get all spreadsheets.
            SpreadsheetFeed feed = service.Query(query);
            foreach (SpreadsheetEntry entry in feed.Entries)
            {
                // return matching spreadsheet
                if (entry.Title.Text.Equals(sheetName))
                {
                    return entry;
                }
            }

            return null;
        }
        public void PopulateNewWorksheet(OAuth2ClientCredentials clientCredentials, string refreshToken, string spreadsheetTitle, string worksheetTitle, ListEntry.Custom[,] listEntries)
        {
            SpreadsheetsService service = GetSpreadsheetService(clientCredentials, refreshToken);

            SpreadsheetQuery query = new SpreadsheetQuery()
            {
                Title = spreadsheetTitle,
            };
            SpreadsheetFeed feed = service.Query(query);

            if (feed.Entries.Count == 0)
                throw new SpreadsheetNotFoundException(string.Format("Spreadsheet with title {0} not found", spreadsheetTitle));

            WorksheetEntry worksheet = CreateWorksheet(worksheetTitle, (uint)listEntries.GetLength(0), (uint)listEntries.GetLength(1), service, feed);

            CellQuery cellQuery = new CellQuery(worksheet.CellFeedLink);
            CellFeed cellFeed = service.Query(cellQuery);

            for (int i = 0; i < listEntries.GetLength(1); i++)
            {
                CellEntry cellEntry = new CellEntry(1, (uint)i + 1, listEntries[0, i].LocalName);
                service.Insert(cellFeed, cellEntry);
            }

            AtomLink listFeedLink = worksheet.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null);
            ListQuery listQuery = new ListQuery(listFeedLink.HRef.ToString());
            ListFeed listFeed = service.Query(listQuery);

            for (int i = 1; i < listEntries.GetLength(0); i++)
            {
                ListEntry row = new ListEntry();
                for (int j = 0; j < listEntries.GetLength(1); j++)
                {
                    if (listEntries[i, j] != null)
                    {
                        listEntries[i, j].LocalName = listEntries[i, j].LocalName.ToLower().Replace(" ","");
                        row.Elements.Add(listEntries[i, j]);
                    }
                }
                LoggerUtil.LogMessage(string.Format("Adding row for {0}", listEntries[i, 0].Value));
                service.Insert(listFeed, row);
            }
        }
Beispiel #29
0
        public string Init()
        {
            StringBuilder sb = new StringBuilder();

            lock (_lockObj)
            {
                if (null == SpreadsheetsService)
                {

                    ApiTraceManager.Inst.LogTrace("Init excel parser");
                    _parameters = new OAuth2Parameters();
                    _parameters.ClientId = ApiUtils.CLIENT_ID;
                    _parameters.ClientSecret = ApiUtils.CLIENT_SECRET;
                    _parameters.Scope = ApiUtils.SCOPE;
                    _parameters.RedirectUri = ApiUtils.REDIRECT_URL;
                    _parameters.TokenExpiry = DateTime.MaxValue;
                    _parameters.AccessType = "offline";
                    _parameters.AccessToken =
                        "ya29.IAK0DqyyBCLy1lNBPHM4ON0m74HiPnXdJnizHC2a7w5CIDndeLPuFbJm0u34HfKpiXZ8UQ";
                    _parameters.RefreshToken = "1/jWXrc6wJ4lUmWscyc3rozkWPKdFwvha43JfPCxMksus";

                    GOAuth2RequestFactory requestFactory = new GOAuth2RequestFactory(null, "MySpreadsheetIntegration-v1",
                        _parameters);
                    SpreadsheetsService = new SpreadsheetsService("MySpreadsheetIntegration-v1");
                    SpreadsheetsService.RequestFactory = requestFactory;
                    sb.AppendFormat("<div>access code={0}</div>", _parameters.AccessCode);
                    sb.AppendFormat("<div>access token={0}</div>", _parameters.AccessToken);
                    sb.AppendFormat("<div>refresh token={0}</div>", _parameters.RefreshToken);

                    SpreadsheetsService service = SpreadsheetsService;
                    SpreadsheetQuery query = new SpreadsheetQuery();
                    SpreadsheetFeed feed = service.Query(query);

                    SpreadsheetEntry entry = GetSpreadsheetEntry(feed);
                    Debug.Assert(null != entry);
                    sb.Append("<h1>" + entry.Title.Text + "</h1>");
                    RenderWeek(entry,service);

                    this.IsInit = true;
                }
            }
            return sb.ToString();
        }
        public void LogIn(string login, string password)
        {
            SpreadsheetsService service = new SpreadsheetsService(applicationName);
            service.setUserCredentials(login, password);

            // Instantiate a SpreadsheetQuery object to retrieve spreadsheets.
            SpreadsheetQuery query = new SpreadsheetQuery();
            query.Title = applicationName;
            try
            {

                SpreadsheetFeed feed = service.Query(query);
                internalCredentials.LogIn(login, password);
            }
            catch (Exception e)
            {
                throw new CredentialsException(e.Message);
            }
        }
        //Fetch all Spreadsheets
        public static ArrayList getSpreadsheetList(string userName, string passWord)
        {
            ArrayList spreadsheetList = new ArrayList();

            SpreadsheetsService service = new SpreadsheetsService("GetSpreadsheetsService");

            //You could set it up from DB or config file also. This is not a reccomended way. Just an easy way to show fetching
            service.setUserCredentials(userName, passWord);

            SpreadsheetQuery query = new SpreadsheetQuery();

            SpreadsheetFeed feed = service.Query(query);

            foreach (SpreadsheetEntry entry in feed.Entries)
            {
                spreadsheetList.Add(entry.Title.Text);
            }

            return spreadsheetList;
        }
Beispiel #32
0
        /// <summary>
        /// @kims 2017.02.09. Added exception handling to smoothly handle abnormal error.
        ///                   If oauth2 setting does not correctly done in the GoogleDataSetting.asset file or missing,
        ///                   you will get the 'Null reference object' error.
        /// @kims 2016.08.09. Added second parameter to pass error message by reference.
        /// </summary>
        /// <returns>Null, if any error has been occured.</returns>
        public IDatabase GetDatabase(string name, ref string error)
        {
            try
            {
                Google.GData.Spreadsheets.SpreadsheetQuery query = new Google.GData.Spreadsheets.SpreadsheetQuery();

                // Make a request to the API and get all spreadsheets.
                SpreadsheetsService service = spreadsheetService as SpreadsheetsService;

                SpreadsheetFeed feed = service.Query(query);

                if (feed.Entries.Count == 0)
                {
                    error = @"There are no spreadsheets in your docs.";
                    return(null);
                }

                AtomEntry spreadsheet = null;
                foreach (AtomEntry sf in feed.Entries)
                {
                    if (sf.Title.Text == name)
                    {
                        spreadsheet = sf;
                    }
                }

                if (spreadsheet == null)
                {
                    error = @"There is no such spreadsheet with such title in your docs.";
                    return(null);
                }

                return(new Database(this, spreadsheet));
            }
            catch (Exception e)
            {
                error = e.Message;
                return(null);
            }
        }
Beispiel #33
0
        public GoogleDatabase GetDatabase(string name, ref string error)
        {
            try {
                Google.GData.Spreadsheets.SpreadsheetQuery query = new Google.GData.Spreadsheets.SpreadsheetQuery();

                // Make a request to the API and get all spreadsheets.
                SpreadsheetsService service = spreadsheetService as SpreadsheetsService;

                SpreadsheetFeed feed = service.Query(query);

                if (feed.Entries.Count == 0)
                {
                    error = "There are no spreadsheets found.";
                    return(null);
                }

                AtomEntry spreadsheet = null;
                foreach (AtomEntry sf in feed.Entries)
                {
                    if (sf.Title.Text == name)
                    {
                        spreadsheet = sf;
                    }
                }

                if (spreadsheet == null)
                {
                    error = string.Format("Spreadsheet: \"{0}\" is not found.", name);
                    return(null);
                }

                return(new GoogleDatabase(spreadsheet));
            }
            catch (Exception e) {
                error = e.Message;
                return(null);
            }
        }
Beispiel #34
0
    // Use this for initialization
    static SpreadsheetEntity()
    {
        if (_RefreshToken == "" && _AccessToken == "")
        {
            Init();
            return;
        }

        Auth();

        Google.GData.Spreadsheets.SpreadsheetQuery query = new Google.GData.Spreadsheets.SpreadsheetQuery();

        // Make a request to the API and get all spreadsheets.
        SpreadsheetFeed feed = service.Query(query);

        if (feed.Entries.Count == 0)
        {
            Debug.Log("There are no spreadsheets in your docs.");
            return;
        }

        AccessSpreadsheet(feed);
    }
    // Use this for initialization
    static SpreadsheetEntity()
    {
        if (_RefreshToken == "" && _AccessToken == "")
        {
            Init();
            return;
        }

        Auth();

        Google.GData.Spreadsheets.SpreadsheetQuery query = new Google.GData.Spreadsheets.SpreadsheetQuery();

        // Make a request to the API and get all spreadsheets.
        SpreadsheetFeed feed = service.Query(query);

        if (feed.Entries.Count == 0)
        {
            Debug.Log("There are no spreadsheets in your docs.");
            return;
        }

        AccessSpreadsheet(feed);
    }
        private void button1_Click(object sender, EventArgs e)
        {
            App.Service.setUserCredentials(this.txtUser.Text, this.txtPass.Text);

            // Instantiate a SpreadsheetQuery object to retrieve spreadsheets.
            SpreadsheetQuery query = new SpreadsheetQuery();

            // Make a request to the API and get all spreadsheets.
            SpreadsheetFeed feed = App.Service.Query(query);

            if (feed.Entries.Count == 0)
            {
                MessageBox.Show("There are no spreadsheets created by this user.","Google Spreadsheets API", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            App.CurrentUser = this.txtUser.Text;
            App.CurrentPassword = this.txtPass.Text;

            var wksListForm = new WorksheetListForm();

            wksListForm.Show();
            this.Close();
        }
 /// <summary>
 ///  overwritten Query method
 /// </summary>
 /// <param name="feedQuery">The FeedQuery to use</param>
 /// <returns>the retrieved SpreadsheetFeed</returns>
 public SpreadsheetFeed Query(SpreadsheetQuery feedQuery)
 {
     return(base.Query(feedQuery) as SpreadsheetFeed);
 }
        //Fetch all worksheets for given Spreadsheet
        public static ArrayList getWorksheetList(string userName, string passWord, string spreadSheetName)
        {
            ArrayList worksheetList = new ArrayList();

            SpreadsheetsService service = new SpreadsheetsService(spreadSheetName + "Service");

            //You could set it up from DB or config file also. This is not a reccomended way. Just an easy way to show fetching
            service.setUserCredentials(userName, passWord);

            SpreadsheetQuery query = new SpreadsheetQuery();

            SpreadsheetFeed feed = service.Query(query);

            foreach (SpreadsheetEntry entry in feed.Entries)
            {
                if (entry.Title.Text == spreadSheetName)
                {
                    AtomLink link = entry.Links.FindService(GDataSpreadsheetsNameTable.WorksheetRel, null);

                    WorksheetQuery wquery = new WorksheetQuery(link.HRef.ToString());
                    WorksheetFeed wfeed = service.Query(wquery);

                    foreach (WorksheetEntry worksheet in wfeed.Entries)
                    {
                        worksheetList.Add(worksheet.Title.Text);
                    }
                }
            }

            return worksheetList;
        }