行のインデントレベルを1に設定できないようです。AddRows
は、InvalidRowLocation
例外をもたらします。 既存の行を更新する場合にのみ、Indent
プロパティを使用することができますInvalidRowLocationスマートシートC#
static string[] DeserializeJson(string json)
{
try
{
SortedDictionary<string, string> values = JsonConvert.DeserializeObject<SortedDictionary<string, string>>(json);
return new string[] { values["Status"], values["ServerIP"], values["ClientIP"], values["Date"] };
}
catch
{
return new string[] { json };
}
}
static Row MakeRow(Sheet sheet, string[] values)
{
List<Cell> cells = new List<Cell>();
Cell cell;
IEnumerator<Column> cols = sheet.Columns.GetEnumerator();
DateTime date;
for (int n = 0; n < values.Length; n++)
{
cols.MoveNext();
Column col = cols.Current;
if (col.Type == ColumnType.DATE)
{
date = DateTime.ParseExact(values[n], dateFormat, CultureInfo.InvariantCulture);
cell = new Cell.AddCellBuilder(col.Id, DateTime.Now).Build();
}
else
cell = new Cell.AddCellBuilder(col.Id, values[n]).Build();
cells.Add(cell);
}
Row row = new Row.AddRowBuilder(null, true, null, null, null).SetCells(cells).Build();
if (values.Length > 1)
row.Indent = 1; // Results in an exception
return row;
}
static void AddRows(SmartsheetClient client, Sheet sheet, string[] lines)
{
List<Row> rows = new List<Row>();
foreach (string line in lines)
rows.Add(MakeRow(sheet, DeserializeJson(line)));
client.SheetResources.RowResources.AddRows(sheetId, rows);
}