none
Table headers not visible when adding data to binding RRS feed

  • Question

  • This is the code that gets run when i click on a button on an office app: 

     
    Office.context.document.bindings.addFromNamedItemAsync("A1:C3", Office.BindingType.Table, { id: "tableBinding" }, function (asyncResult) {
                var binding = asyncResult.value;
                var myTable = new Office.TableData();
                myTable.headers = [["Name", "Price", "Quantity"]];
                myTable.rows = [["Apple", "843", "2"], ['Microsoft', '2', '0']];
                Office.select("bindings#tableBinding").setDataAsync(myTable, {tableOptions: { headerRow: true, bandedRows: true, style: "TableStyleLight1" } }, function (asyncResult2) {
                });
                });
    

    The code loads the table successfully but does not apply any of the formatting to the table. None of the header rows are visible. I have tried using setTableOptionsAsync but this just crashes excel everytime it is executed. Why aren't any of the table formats being applied? Also when i add a break point and view the binding object after the setDataAsync method call, i notice that the hasHeaders property is false. It is a read-only property so I can't even modify it. I just want a way to make sure that the table headers are visible when I add data to a tableBinding.

    thanks

    Thursday, July 31, 2014 7:58 AM

Answers

  • Hi,

    Please try:

    Office.context.document.bindings.addFromNamedItemAsync("A1:C3", Office.BindingType.Table, { id: "tableBinding" }, function (asyncResult) {
                var binding = asyncResult.value;
                var myTable = new Office.TableData();
                myTable.headers = [["Name", "Price", "Quantity"]];
                myTable.rows = [["Name", "Price", "Quantity"],["Apple", "843", "2"], ['Microsoft', '2', '0']];
                Office.select("bindings#tableBinding").setDataAsync(myTable, { tableOptions: { headerRow: true, bandedRows: true, style: "TableStyleLight1" } }, function (asyncResult2) {
                });
            });

    The result:

    If you define the table header, the header will not be displayed, you need to push them into table data.

    Hope this helps.


    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.


    Friday, August 1, 2014 6:24 AM
    Moderator

All replies

  • Hi,

    Please try:

    Office.context.document.bindings.addFromNamedItemAsync("A1:C3", Office.BindingType.Table, { id: "tableBinding" }, function (asyncResult) {
                var binding = asyncResult.value;
                var myTable = new Office.TableData();
                myTable.headers = [["Name", "Price", "Quantity"]];
                myTable.rows = [["Name", "Price", "Quantity"],["Apple", "843", "2"], ['Microsoft', '2', '0']];
                Office.select("bindings#tableBinding").setDataAsync(myTable, { tableOptions: { headerRow: true, bandedRows: true, style: "TableStyleLight1" } }, function (asyncResult2) {
                });
            });

    The result:

    If you define the table header, the header will not be displayed, you need to push them into table data.

    Hope this helps.


    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.


    Friday, August 1, 2014 6:24 AM
    Moderator
  • Then what is the point of having headers?
    Friday, August 1, 2014 8:02 AM
  • Hi

    Do you want to format table header?

    If so, please refer to How to: Format tables in apps for Excel.

    Hope this helps.


    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.

    Friday, August 1, 2014 8:31 AM
    Moderator