Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old February 19th, 2002, 07:00 AM
sgaucho sgaucho is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Posts: 26 sgaucho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 28 sec
Reputation Power: 0
excel

Hi,

I need to open an Excel (csv file) in an excel spreadsheet and shown in a browser when clicked on a link..

can anyone pl provide suggestions??

TIA,

sands

Reply With Quote
  #2  
Old February 19th, 2002, 07:03 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,711 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 6 Days 4 h 53 m 59 sec
Reputation Power: 259
Use a jsp to set proper MIME type and it will open Excel as a plugin.
Take a look at this php example http://www.judas-price.de/scripts/mysql2xls.dhtml

Reply With Quote
  #3  
Old February 19th, 2002, 07:07 AM
sgaucho sgaucho is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Posts: 26 sgaucho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 28 sec
Reputation Power: 0
hi ,

i tried response.setContentType("application/vnd.ms-excel");

and when I dump some text within the file it does open it in an excel spreadsheet but am unable to make it work with a file stored in the oracle DB..

any suggestions??

TIA,

gaucho

Reply With Quote
  #4  
Old February 19th, 2002, 07:13 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,711 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 6 Days 4 h 53 m 59 sec
Reputation Power: 259
Why didn't you look at the example provided?
After setting mime type you have to read the file and send it to browser.

Reply With Quote
  #5  
Old February 19th, 2002, 08:12 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,711 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 6 Days 4 h 53 m 59 sec
Reputation Power: 259
You can find a java example here http://www.jguru.com/faq/view.jsp?EID=502939

full of errors, at least

public class DownloadServlet extends HttpServlet
{

public void doGet(HttpServletRequest request, HttpServletResponse response)

Reply With Quote
  #6  
Old February 19th, 2002, 11:13 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,711 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 6 Days 4 h 53 m 59 sec
Reputation Power: 259
This works, even if not perfectly, on my Win98se+Tomcat+JDK1.3.1_2 PC
[java]
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;

public class DownloadServlet extends HttpServlet
{

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
int length;
byte[] buf = new byte[1024];
BufferedInputStream in =
new BufferedInputStream(new FileInputStream("C:\\LPServer\\jakarta-tomcat-3.2.3\\webapps\\ROOT\\test.csv"));


ServletOutputStream out =
response.getOutputStream();

response.setContentType("x-application/vnd.ms-excel");
//response.setContentLength(size);
// see http://www.faqs.org/rfcs/rfc1806.html
response.addHeader("Content-Disposition", "inline; filename=\" test.csv "\"");

// copy data
while ((in != null) && ((length = in.read(buf)) != -1))
{
out.write(buf, 0, length);
}
}
}
[/java]
Adapted from the example before.
I'll work out a better option later!

Reply With Quote
  #7  
Old February 19th, 2002, 12:01 PM
sgaucho sgaucho is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Posts: 26 sgaucho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 28 sec
Reputation Power: 0
got it to work finally..

<%

String a ="Content-type: ";

response.setContentType(contype);
long index = 1;

while(index < doc.length()){
response.getOutputStream().write(doc.getBytes(index,100));
index+=100;

}

%>

PHP is far easier and simpler... and outputting BLOB is pretty different too!!

Reply With Quote
  #8  
Old February 21st, 2002, 07:42 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,711 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 6 Days 4 h 53 m 59 sec
Reputation Power: 259
OK, I'm just playing around with your original question, and came out with this, using SQL should be more flexible:
Quote:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;

public class DBServlet extends HttpServlet {

private static final String DB_DRIVER = "org.relique.jdbc.csv.CsvDriver";
private static final String DB_URL = "jdbc:relique:csv:c:\\WINDOWS\\Desktop\\excelread";


public void init(ServletConfig config) throws ServletException {
try {
Class.forName(DB_DRIVER);
} catch (ClassNotFoundException ex) {
throw new UnavailableException("JDBC Driver " + DB_DRIVER + " not found.");
}
}

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
try {
//Properties props = new Properties();
//props.put("separator",";");
// create a connection. The first command line parameter is assumed to
// be the directory in which the .csv files are held
//Connection conn = DriverManager.getConnection("jdbc:relique:csv:c:\\WINDOWS\\Desktop\\excelread",props);
Connection conn = DriverManager.getConnection("jdbc:relique:csv:c:\\WINDOWS\\Desktop\\excelread");
// execute statements (and process results)
String query = "select * from test";
Statement st = conn.createStatement();
ResultSet myResultSet = st.executeQuery(query);
//output to excel
ServletOutputStream out = response.getOutputStream();
response.setContentType("application/vnd.ms-excel");
//response.setContentLength(size);
// see http://www.faqs.org/rfcs/rfc1806.html
response.addHeader("Content-Disposition", "inline; filename=\"test.csv\" ");
if (myResultSet != null) {
while (myResultSet.next()) {
// specify the field name
String name = myResultSet.getString("pippo");
out.println(name);
}
}
conn.close();
}
catch (SQLException ex) {
// handle exception
// Printout root SQLException
System.err.println("An SQL exception occurred: " + ex);

// Get all chained SQLExceptions
while((ex = ex.getNextException()) != null)
{
System.err.println("Contained reason: " + ex);
}

}
}

}


It reads a file like
pippo,pluto,minnie,topolino
we,12,12,12
12,we,12,12
where first row is like column names.
Your opinion?
Thanks in advance

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > excel


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

IBM developerWorks




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway