I have a table where your data is changed every week, and in some cells it is null, occasionally it is bringing me an error because apparently it can only read values that are not null, I would like to know how I can read it anyway, even if it doesn't bring me any data.
i want to read the E2 null cell for example.
what i have did so far in my project
{
UserCredential credential;
using (var stream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
{
string creadPath = "token.json";
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(creadPath, true)).Result;
label1.Text = "Conected with sheet";
}
var service = new SheetsService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName
});
{
var LimiteOP = $"{sheet}!B3:E3";
SpreadsheetsResource.ValuesResource.GetRequest request = service.Spreadsheets.Values.Get(SpreadSheetId, LimiteOP);
var response = request.Execute();
IList<IList<Object>> values = response.Values;
if (values.Count > 0)
{
foreach (var row in values)
{
Console.WriteLine(row[0]+" "+ row[1]+" " + row[2]);
}
}
else
{
Console.WriteLine("Nothing");
}
Update (from comments): "the consolewrite give the exception"
EDIT
to solve the problem that was the way as a simple process, transform the object
to a string
and then use a Split
to remove the null spaces
String[] str = row[0].ToString().Split(null);
Console.WriteLine(str[0]);