Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Opening Excel file from within Java program

 
Greenhorn
Posts: 7
Eclipse IDE Firefox Browser Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. I'm completing a program which to make a long story short retrieves data from an Oracle database and outputs this to a flat file(*.csv) which in turn will be used in Excel 97 for reports. I was wondering what the best way of going about opening this file up for viewing in Excel through my Java program would be(i.e. clicking "File") instead of finding the file manually outside of the Java program and double clicking it. Any thoughts?

THX in advance...
Z
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might be able to run excel with a command line argument of the csv file.

Make sure that the csv file is in a format that excel can understand. The format for excel csv is a bit different than most. I have written libraries to help out with csv files. You can get them here:
http://ostermiller.org/utils/CSVLexer.html
 
Michael Mathewson
Greenhorn
Posts: 7
Eclipse IDE Firefox Browser Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Steve. Thanks for the quick response. I just tried your idea and it works great! I was wondering though(now...), everybody that's gonna use this program has the same image(I work at a college and this assumption is quite accurate), but, what if per chance they don't have 'excel.exe' where 99% of people do... is there a way to find it? I'll have no problem creating the dynamic filenames(cause they'll be different all the time) but what about the .exe? This question is just out of curiosity...

THX
Mike
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you tell the command shell to "start" the .csv file, it will use whatever application is associated with .csv files; if they don't have Excel but they do have Works or something else then that's what would be used. This is one of the cleaner ways to do this as it works with any application that knows about csv files and not just Excel.
On WinNT, the code would be something likeOn Win9*/Me, the command interpreter is command.com. The COMSPEC environment variable will tell you which of the two you need to use.
- Peter
[ March 19, 2002: Message edited by: Peter den Haan ]
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic