Question

m41in4 on Fri, 22 Apr 2016 14:48:06


Hi,

I have a situation where I need to remove all rows (except header) from table, using deleteAllDataValuesAsync function, and then I need to create new rows using addRowsAsync function. In Excel everything works perfectly fine. But when it comes to Word, in case where table has only one column, only header remains bound, where rest of the rows doesn't. In case where table has multiple columns again everything works perfectly fine.

Initially I thought that there is a bug in my code, so I tested this on brand new project and still got same result.

I hope that you will check this, if you need any additional informations, I'll provide it.

Best Regards,

Milos


Sponsored



Replies

David_JunFeng on Mon, 25 Apr 2016 07:08:43


>>>But when it comes to Word, in case where table has only one column, only header remains bound, where rest of the rows doesn't. In case where table has multiple columns again everything works perfectly fine.

According to your description, I have made a sample to try to reproduce this issue, unfortunately, I can't. So I suggest that you could provide sample code and screenshot to help us reproduce and resolve your issue.

Thanks for your understanding.

m41in4 on Mon, 25 Apr 2016 12:41:37


Hi David,

Thank you for reply. First of all I forgot to mention that I'm using Word 2016 (not online), on Windows 7, guess this information is also relevant.

Here is my code: 

            var binding;

            $('#addBindingButton').click(function () {
                Office.context.document.bindings.addFromSelectionAsync(Office.BindingType.Table, function (result) {
                    binding = result.value;
                    binding.addHandlerAsync(Office.EventType.BindingSelectionChanged, function (result) {
                        app.showNotification('binding selection changed ' + result.binding.id);
                    });
                });
            });

            $("#updateButton").click(function () {
                binding.deleteAllDataValuesAsync(function (result) {
                    var rows = [];
                    if (binding.columnCount === 1) {
                        rows = [["1"], ["2"]];
                    } else if (binding.columnCount === 2) {
                        rows = [["1", "2"], ["3", "4"]];
                    }

                    binding.addRowsAsync(rows, function (result) {
                        binding.addHandlerAsync(Office.EventType.BindingSelectionChanged, function (result) {
                            app.showNotification('binding selection changed ' + result.binding.id);
                        });
                    });
                });
            });

I also uploaded video with all the steps which cause the problem: 

https://www.youtube.com/watch?v=IutD23MTI9o


Best Regards,

Milos






David_JunFeng on Tue, 26 Apr 2016 07:01:07


Hi, m41in4

Thanks very much for your detail steps to help us reproduce this issue. I’m able to reproduce this issue now. This workaround is you could rebind to a region of a document that contains a table with headers.

In addition if you have any feedback for Office Dev, please feel free to submit them to User Voice:

https://officespdev.uservoice.com/

Thanks for your understanding.

m41in4 on Tue, 26 Apr 2016 10:31:17


This workaround is you could rebind to a region of a document that contains a table with headers.
But if I do that, and let's say move the table to different page, and write some text at the place where table was before, then if I select that text, it will be recognized as a table if I'm not mistaken. So that could be a problem.

Anyway, I've posted the problem at  https://officespdev.uservoice.com/
Thank you for your help, and quick responses, and have a nice day.