jpillora / node-edit-google-spreadsheet

A simple API for editing Google Spreadsheets
304 stars 101 forks source link

Question: getting computed formula values, not the formula #74

Closed deedubbleyoo closed 9 years ago

deedubbleyoo commented 9 years ago

Hi, I was reading the API docs here: https://developers.google.com/google-apps/spreadsheets/data and noticed that the XML can provide two values: inputValue and numericValue.

I've managed to authenticate with OAuth2 successfully, and have a basic setup similar to the example in the docs:

spreadsheet.load({
    debug: true,
    spreadsheetId: '1bgsoZX7NDQML_LC9yHpH_StDUDrX4NmmKX7pVJGKnrg',
    worksheetId: 'oa9va38',
    oauth2: {
    /* jshint camelcase: false */
        client_id: auth.clientID,
        client_secret: auth.clientSecret,
        refresh_token: auth.refreshToken
    },
    useCellTextValues: true

}, function (err, spreadsheet) {
    if(err) {throw err;}

    spreadsheet.receive(function(err, rows, info) {
        if(err) {throw err;}
        console.log('Found rows:', rows);
        return rows;
    });
});

However in the console, all I am getting are the literal formulas, not the computed values. I assumed that the useCellTextValues option flag switches between them, but it doesn't seem to change the output. Can you help?

Otherwise, is there any other way to get the numericValue?

andreconrado commented 9 years ago

Try this:

spreadsheet.load({
    debug: true,
    spreadsheetId: '1bgsoZX7NDQML_LC9yHpH_StDUDrX4NmmKX7pVJGKnrg',
    worksheetId: 'oa9va38',
    oauth2: {
    /* jshint camelcase: false */
        client_id: auth.clientID,
        client_secret: auth.clientSecret,
        refresh_token: auth.refreshToken
    },
    useCellTextValues: true

}, function (err, spreadsheet) {
    if(err) {throw err;}
    // { getValues: true }
    spreadsheet.receive( { getValues: true } ,function(err, rows, info) {
        if(err) {throw err;}
        console.log('Found rows:', rows);
        return rows;
    });
});
deedubbleyoo commented 9 years ago

This seems to have worked, thank you very much for your help!