3

what is the most efficient way to create a xls file in a jsp page?

I created an xls file using poi in jsp page, but if not the most efficient.

Thanks

Maria José
  • 87
  • 3
  • 13
  • Related: [JSP generating Excel spreadsheet (XLS) to download](http://stackoverflow.com/questions/477886/jsp-generating-excel-spreadsheet-xls-to-download/2154226#2154226). – BalusC Jul 10 '10 at 00:54

2 Answers2

2

A lot of times when I need to make an xls file, I create a CSV file instead and use that to generate the XLS. Obviously, creating comma-separated values is very simple and importing / opening a plain-text CSV file as an Excel document is equally easy.

I hope that helps in some way,

--gMale

gMale
  • 17,147
  • 17
  • 91
  • 116
  • He might not be aware about the ease of CSV. – BalusC Jul 10 '10 at 03:43
  • thanks !!, But when the user opens the file as xls not see with commas? – Maria José Jul 10 '10 at 03:44
  • no commas; but sometimes it's tricky to make Excel to show strings of specific formats as strings -- it "intelligently" converts them into dates, or numbers. – Vladimir Dyuzhev Jul 10 '10 at 03:48
  • when more formatting is needed, I tend to use Excel templates (create an Excel file with all the proper & pretty formatting, save it as a template. Done.). I haven't done it in a long time but I remember it's very easy in VBA to open a workbook as a template for another workbook. It's like 2-3 lines of code. – gMale Jul 10 '10 at 04:05
0

For cases more complex than CSV can handle (e.g. colourful formatting) I generate XML-based XLS file, which is very simple, almost like writing out HTML.

I never studied the format. Instead, I manually create the file in Excel, save it as XML, and write a code that produces a file of the same structure.

Vladimir Dyuzhev
  • 18,130
  • 10
  • 48
  • 62