This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CSV file to open in Excel

 
Brian Nice
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having trouble getting a CSV file to open up in Excel. I have a .jsp page that links to another JSP page that has the following:
========
<%@ page language="java" session="true" isErrorPage="false" %>
<html>
<head>
<title>Delivery Status</title>
</head>
<body>
<% response.setContentType("application/vnd.ms-excel"); %>
<jsp:include page="./config/mydomain/reports/Plane_US1A.csv" />
</body>
</html>
========
It launches excel, but it always comes up blank. We are running on Weblogic 6.1 server on Unix and the .csv files are placed in a directory from another application. I've tried the content type as suggested by other people as "text/csv" or "text/comma-saparated-values", but they just prompt me with a dialog box to save the file.
Any suggestions would be greatly appreciated
Thanks!
Brian
 
Michael Zalewski
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you change the .csv file to be formatted like an HTML table? If you can, you will find that it works great without any changes, unless your users are using really *old* versions of Excel. Excel 97 and above understand data formatted as an HTML table. If you do this, Excel will even recognize the cell backgrounds, fonts, colors, embedded hyperlinks, etc.
If not, you need to get rid of the HTML tags. I haven't actually tested the following, but it should be close:
Two things to note. 1) The funny way scriptlet tags are opened (the <% is at the end of a line instead of the beginning) is important. If you don't do that, your downloaded CSV file will contain blank lines in the front, which will give blank rows in your excel spreadsheet. 2) The if( true) return at the end of the last scriptlet is also important, so that you don't get blank lines and trailing spaces at the end of the CSV file.
[ December 02, 2002: Message edited by: Michael Zalewski ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic