1

I am continuing from my previous question I need a way to export my json string into a xls or csv file that can be opened in MS Excel (I am using simple html and jsp).

So far I found this link that made me open a excel using

var xls = new ActiveXObject("Excel.Application");
    xls.visible = true;

Any type of suggestions is welcome. Thankyou

Community
  • 1
  • 1
AabinGunz
  • 12,109
  • 54
  • 146
  • 218
  • 2
    Not on the client, unless you only want IE support. Ask the server to generate a file and give the client a download link. – Raynos Jul 19 '11 at 12:00
  • @Raynos: Where can I find out that it will only support IE? do you mean `ActiveXObject` will only support IE? – AabinGunz Jul 20 '11 at 05:34

1 Answers1

1

I'm not familiar with xls format so I can't give a code example, but you can use handlebars.js http://www.handlebarsjs.com/ which is a small and simple json -> xml templating engine.

EDIT:

I was under the false impression that xls files were xml. So unless excel has the ability to import xml, you should create the xls server-side with something like this http://pizzaseo.com/php-excel-creator-class. You can do with with ajax to make it transparent to the user.

EDIT:

Excel can import xml files so you can use handlbars.js http://www.handlebarsjs.com/ to easily convert json to xml. However if that's not an option, you should look into POI http://poi.apache.org/ which is a JAVA api for Microsoft documents.

Ilia Choly
  • 18,070
  • 14
  • 92
  • 160
  • Thanks for your answer, also I am using java and struts2 on server side – AabinGunz Jul 20 '11 at 05:30
  • K I am using POI so I should send the stream to client side! then in client side what should i do? – AabinGunz Jul 21 '11 at 10:28
  • You'd create the file on the server, then do something like `window.location = http://yourserver.com/file.xls` once it's done to start the download. – Ilia Choly Jul 21 '11 at 13:07