InvalidRowLocation Smartsheet C#

InvalidRowLocation Smartsheet C#

似乎无法将一行的缩进级别设置为 1。AddRows 导致 InvalidRowLocation 异常。

    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);
    }

更新 现有 行时,您只能使用 Indent 属性。由于您要添加新行,因此需要设置 ParentId 属性。请参阅文档:http://smartsheet-platform.github.io/api-docs/#row-location

在 Smartsheet 中缩进会在行之间创建 "parent-child" 关系。因此,要缩进一个新行,您需要将其父行的 rowId 作为 parentId。

看起来像这样

 Row row = new Row.AddRowBuilder(null, true, 7531436244775314, null, null).SetCells(cells).Build();