I am trying to read google spreadsheet in our application and which working
fine as of now.
However, how can I find specific cell based on the value provided and
reading the spreadsheet from that cell. For e.g. Spreadsheet contains 100
rows having data for 2 columns(Name, City).
So I need to find cell id from Name column. For e.g. Name = 'John' returns
CellID as 'A50'.Then I will start reading the spreadsheet from A50.
Below is my code where I have reading the data from hardcoded cell id/range
static string[] DocsScopes = { SheetsService.Scope.SpreadsheetsReadonly
};static string ApplicationName = "Other client 2";
private static void ReadExcelSheet()
{
UserCredential credential;
using (var stream = new FileStream("credentials.json",
FileMode.Open, FileAccess.Read))
{
string credPath = "token.json";
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
DocsScopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
Console.WriteLine("Credential file saved to: " + credPath);
}
// Create Google Sheets API service.
var service = new SheetsService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
// Define request parameters.
string spreadsheetId =
"1_kJmQsQ2tQxTe0K8upz3byrfSfQ9db_jIitvq3wqsaza8Yzo";
string range = "Sheet1!A2:B";
SpreadsheetsResource.ValuesResource.GetRequest request =
service.Spreadsheets.Values.Get(spreadsheetId, range);
ValueRange response = request.Execute();
IList<IList<object>> values = response.Values;
if (values != null && values.Count > 0)
{
foreach (var row in values)
{
Console.WriteLine("{0}, {1}", row[0], row[1]);
}
}
else
{
Console.WriteLine("No data found.");
}
Console.Read();
}
--
You received this message because you are subscribed to the Google Groups
"Google Spreadsheets API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.