Save JQuery Handsontable to an excel file on serve

2020-03-31 13:39发布

Im looking for a solution in which you can save data entered using this jquery plugin http://handsontable.com/ to a file on the server.

Simply put they type in some data, click a save button and the file is written to a specified folder on the server. Obviously the second part would be to open the file later and import it back into the jquery plugin table but still on step 1 here... the real goal is to just make this data useable for someone outside of the plugin. Any help or pointers would be greatly appreciated. I've search this topic and I cant seem to find any solutions.

Thanks for your help!

1条回答
神经病院院长
2楼-- · 2020-03-31 14:37

What your trying to do is certainly possible however there are a number of steps involved.

  • Handsontable seems to have a method called handsontable.getData().

You can see in the Load & Save example they use this method to 'get the data' from the handsontable and insert it into the ajax function.

  • Use a Ajax function to pass this data to a server side script.

Once your happy you can get the data, it needs to be passed to a server side script for further processing. This can be achieved using Ajax and POST or GET variables. For this step you can pretty much copy parts of their example. Otherwise Jquery has a nice Ajax function you could use.

  • Write a processing script to format the data in a CSV format and write it to a file.

Once you can confirm the data is getting to your server side script you need to encode it in a CSV format. Some server side languages have functions to help you do this. Once you have the data in the right format, you can write it to a file.

Keep in mind this wont produce a .xls file, it will make a .csv which is about as good as you will get with minimal fuss and will certainly be useful for people outside of the plugin. If you want to learn more about this sort of thing then you should take a look at submitting forms with ajax since this is essentially what your doing only more complex.

查看更多
登录 后发表回答