I have a list of string with data. My mission is simple: need to write data from list to rows starts with A2 cell.
I found the code on internet, but the code only allows to write one value to a one cell.
I need to write a list of strings starting from cell A2.
Please help me.
This code solved my problem:
public void AddRow(int length, List<string> headers, List<string> prices)
{
// Setting Cell Name...
string range = "";
var dt = DateTime.Now;
for (int i = 0; i < length - 1; i++)
{
dt = DateTime.Now;
range = $"Sheet44!A{i + 1}";
var valueRange = new ValueRange();
// Setting Cell Value...
var oblist = new List<object>() { headers[i] };
valueRange.Values = new List<IList<object>> { oblist };
// Append the above record...
var appendRequest = _sheetsService.Spreadsheets.Values.Append(valueRange, _spreadsheetId, range);
appendRequest.ValueInputOption = SpreadsheetsResource.ValuesResource.AppendRequest.ValueInputOptionEnum.USERENTERED;
//var appendReponse = appendRequest.Execute();
do
{
} while (dt + TimeSpan.FromSeconds(1) > DateTime.Now);
appendRequest.Execute();
dt = DateTime.Now;
range = $"Sheet44!B{i + 1}";
var valueRange2 = new ValueRange();
var oblist2 = new List<object>() { prices[i] };
valueRange.Values = new List<IList<object>> { oblist2 };
// Append the above record...
appendRequest = _sheetsService.Spreadsheets.Values.Append(valueRange, _spreadsheetId, range);
appendRequest.ValueInputOption = SpreadsheetsResource.ValuesResource.AppendRequest.ValueInputOptionEnum.USERENTERED;
//var appendReponse = appendRequest.Execute();
do
{
} while (dt + TimeSpan.FromSeconds(1) > DateTime.Now);
appendRequest.Execute();
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…