Apostrophe is added when creating formula in Googl

2019-03-05 19:30发布

问题:

When I create a formula in Google Sheets via C#, the formula gets prepended with an apostrophe like so:

'=SUM(B3:B5)

With that apostrophe in the beginning, the formula is treated as string so it does not do what it is supposed to do. Can you help? Below is my code.

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

Thank you.

回答1:

I got it. You just need to change the "RAW" to "USERENTERED" like this

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