How can I export (as CSV) updated formula references after column move?

Tags: #<Tag:0x00007efc6540a930> #<Tag:0x00007efc6540a7a0>

Hello,

additional question for:

How can I export (as CSV) updated formula references after column move?
I am currently using this code:

hot.getPlugin('exportFile').exportAsString('csv',
{ ... }
);

But I can not see in CSV Export the updated formula. Do you have any solution for that?

Thank you.

Hi @HakanAkkurt

This solution should work: https://jsfiddle.net/handsoncode/k39a7Ljd/ It will update the source data after the columns movement so when you export the table to CSV file after moving the column you should now get the updated formula.

Thank you for your answer. When I move now Column B behind Column D my output is:

[["=5+D1", 5, 11, 12]]

Yes, the formula is updated correctly but I have expected this output:

[["=5+D1", 11, 12, 5]]

Because Column B with value 5 is now Column D with value 5, but this value order is not updated correctly.

Can we fix that ?

@HakanAkkurt

That would be more complicated as it turns out that HyperFormula save the reformatted formula into the source data, but Handsontable doesn’t do the same, but there’s a reason for this. As while me move the columns only the visual layer of the data is being modified, and the source data stays intact. That’s a a design choice, and to save the visual data to the source with correct column reindexing would require more customization. We don’t have any guides or examples for such scenario, but if you decide to implement this solution you might need to use the indexMapper: https://handsontable.com/docs/react-data-grid/api/index-mapper/ and hooks and methods like listed below:

Another advice would be to gather only the data from the columns that were moved and keep the formulas in another array to finally join them and update the whole source data in afterColumnMove hook: https://handsontable.com/docs/react-data-grid/api/hooks/#aftercolumnmove

Ok, I will check, thanks for your answer.