Hello,
I want to build excel spreadsheet with servlet programming. I used tab-separated data for excel.
response.setContentType("application/vnd.ms-excel");
PrintWriter out=response.getWriter();
out.println("\t\tFruits");
out.println("\tName\tPrice");
out.println("\tApples");
out.println("\tMangoes");
My query is that i want the title fruits to be in the center i mean i want to merge the cell. I want the output of Fruits from cell B2 to D2.What wld i have to update for merging the cell.
I know if we create a tabular data then it takes rowspan and colspan attribute but for this what to use??
If you want to produce a complete, fully compatibile Excel file you should use Apache POI and create that file with this library. It’s very easy to do – just take a look at the guides here.
And then you can use the code above to make a downloadable file for the user, i.e.:
There is a complete example of such servlet here
And if it can be XLSX file, you can use this example as well.
But if You still want to use CSV/TSV files, you can still easily do so.
As one can see there is a difference in
Content-Dispositionsection above.BTW, if one wants to generate CSV data one can use a great little library from Ostermiller which will format the CSV/TSV file in the way that Excel will understand fully.