none
setSelectedDataAsync Error using Office.TableData - The supplied data object type is not supported. RRS feed

  • Question

  • I have difficult time creating table objects. The examples I see are setting manually constructed arrays of strings and I need to use imported data. So I had a ADODB.recordset from an on-premise database and I made an array of rows (call it sqlArr) which were arrays of fields using jQuery.makeArray() for both arrays. I created a Office.Table object (tableData) that I want to set in an Excel spreadsheet. I added the headers successfully (but inelegantly) by adding each individual item of the first array (rows[0]) in sqlArray:

    tableData.headers = [hdrFields[0], hdrFields[1], hdrFields[2], hdrFields[3], hdrFields[4], hdrFields[5], hdrFields[6], hdrFields[7], hdrFields[8], hdrFields[9], hdrFields[10], hdrFields[11]];

    If I add no row data to the Table object, setSelectedDataAsync sets a nice header on the Excel sheet so I know it is the rows property that is hanging me up.

    After unsuccessfully pushing row arrays (rows[i]) in their entirety I tried this:

    var recFields = rows[i];
    tableData.rows.push([recFields[0], recFields[1], recFields[2], recFields[3], recFields[4], recFields[5], recFields[6], recFields[7], recFields[8], recFields[9], recFields[10], recFields[11]]);

    Still no luck. Can someone please review this object and tell me why it is erroring out as not supported?


    John Donnelly

    Here's a better picture of the object:

    • Edited by J_Donnelly Thursday, September 17, 2015 4:24 PM Smaller Picture
    Thursday, September 17, 2015 4:19 PM

Answers

  • Hi J_Donnelly,

    With your screenshot, I found you did not set any value for the last element “solddate”. As my test, it will generate error with something like this “myTable.rows = [['Berlin1', ], ['Roma1', ], ['Tokyo1', ]];”. If there is no value for “solddate”, I suggest you supply empty value for it like this “myTable.rows = [['Berlin1',''  ], ['Roma1', '' ], ['Tokyo1', '']];”.

    Here is a simple demo:

    //add tabledata
    function addTableData() {
        // Build table.
        var myTable = new Office.TableData();
        //myTable.headers = [["Cities"]];
        //myTable.rows = [['Berlin'], ['Roma'], ['Tokyo'], ['Seattle']];
        myTable.headers = [["C1", "C2"]];
        //one row
        //myTable.rows = [['Berlin1', 'Berlin2']];
        //multiple rows
        myTable.rows = [['Berlin1',''  ], ['Roma1', '' ], ['Tokyo1', '']]; //this is right 
        //myTable.rows = [['Berlin1', ], ['Roma1', ], ['Tokyo1', ]];//this is wrong
        // Write table.
        Office.context.document.setSelectedDataAsync(myTable, { coercionType: "table" },
            function (result) {
                var error = result.error
                if (result.status === "failed") {
                    app.showNotification(error.name + ": " + error.message);
                }
            });
    }

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Marked as answer by J_Donnelly Friday, September 18, 2015 4:17 AM
    Friday, September 18, 2015 2:41 AM

All replies

  • Hi J_Donnelly,

    With your screenshot, I found you did not set any value for the last element “solddate”. As my test, it will generate error with something like this “myTable.rows = [['Berlin1', ], ['Roma1', ], ['Tokyo1', ]];”. If there is no value for “solddate”, I suggest you supply empty value for it like this “myTable.rows = [['Berlin1',''  ], ['Roma1', '' ], ['Tokyo1', '']];”.

    Here is a simple demo:

    //add tabledata
    function addTableData() {
        // Build table.
        var myTable = new Office.TableData();
        //myTable.headers = [["Cities"]];
        //myTable.rows = [['Berlin'], ['Roma'], ['Tokyo'], ['Seattle']];
        myTable.headers = [["C1", "C2"]];
        //one row
        //myTable.rows = [['Berlin1', 'Berlin2']];
        //multiple rows
        myTable.rows = [['Berlin1',''  ], ['Roma1', '' ], ['Tokyo1', '']]; //this is right 
        //myTable.rows = [['Berlin1', ], ['Roma1', ], ['Tokyo1', ]];//this is wrong
        // Write table.
        Office.context.document.setSelectedDataAsync(myTable, { coercionType: "table" },
            function (result) {
                var error = result.error
                if (result.status === "failed") {
                    app.showNotification(error.name + ": " + error.message);
                }
            });
    }

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Marked as answer by J_Donnelly Friday, September 18, 2015 4:17 AM
    Friday, September 18, 2015 2:41 AM
  • It works! Thanks.

    John Donnelly

    Friday, September 18, 2015 4:17 AM