使用C#在Google电子表格中创建公式时添加了撇号

时间:2016-12-29 05:17:09

标签: c# google-sheets-api

当我通过C#在Google表格中创建公式时,公式会附加一个撇号,如下所示:

'=SUM(B3:B5)

在开头使用该撇号时,公式被视为字符串,因此它不会执行它应该执行的操作。你能帮我吗?以下是我的代码。

        var formula1 = "=SUM(B3:B5)";
        var formula2 = "=SUM(C3:C5";
        var formula3 = "=MAX(D3:D5)";

        List<object> list1 = new List<object>() { "Item", "Cost", "Stocked", "Ship Date" };
        List<object> list2 = new List<object>() { "Wheel", "$20.50", "4", "3/1/2016" };
        List<object> list3 = new List<object>() { "Door", "$15", "2", "3/15/2016" };
        List<object> list4 = new List<object>() { "Engine", "$100", "1", "30/20/2016" };
        List<object> list5 = new List<object>() { "Totals", formula1, formula2, formula3 };
        IList<IList<Object>> list = new List<IList<Object>>() { list1, list2, list3, list4, list5 };

        ValueRange VRange = new ValueRange();
        VRange.Range = range;
        VRange.Values = list;

        SpreadsheetsResource.ValuesResource.AppendRequest ar = service.Spreadsheets.Values.Append(VRange, spreadsheetId,range);
        ar.ValueInputOption = SpreadsheetsResource.ValuesResource.AppendRequest.ValueInputOptionEnum.RAW;
        var response2 = ar.Execute();

谢谢。

1 个答案:

答案 0 :(得分:2)

我明白了。您只需将“RAW”更改为“USERENTERED”,就像这样

ar.ValueInputOption = SpreadsheetsResource.ValuesResource.AppendRequest.ValueInputOptionEnum.USERENTERED;