Results 1 to 5 of 5
Thread: How do you create an excel file?
- 10-11-2009, 01:30 PM #1
Member
- Join Date
- Oct 2009
- Location
- Rotterdam
- Posts
- 52
- Rep Power
- 0
How do you create an excel file?
I've been trying out making the infamous Point class, along with a program to check the distances between some.
The program:
The Point class:Java Code:import java.io.*; class TestDistance { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int i,j; double temp; Point p[] = new Point[5]; System.out.println("Enter the coordinates"); for (i = 0; i < p.length; i++) { System.out.print("Point" + (i + 1) + ":(x):"); temp = Double.parseDouble(in.readLine()); System.out.print(" (y):"); p[i] = new Point(temp, Double.parseDouble(in.readLine())); } double distances[][] = new double[p.length][p.length]; for (i = 0; i < p.length; i++) { for (j = 0; j < p.length; j++) { distances[i][j] = p[i].distance(p[j]); } } } }
I want to display the distances array, but don't get me started about the command prompt. It is very frustrating being able to easily create an array like that, but not being able to display it properly.Java Code:class Point { private double x; private double y; public Point(double getx, double gety) { x = getx; y = gety; } public double GetX() { return x; } public double GetY() { return y; } public void SetX(int myx) { x = myx; } public void SetY(int myy) { y = myy; } public boolean equals(Point p) { return (x == p.GetX() && y == p.GetY()); } public double distance(Point p) { double distancex = (p.GetX() - x); double distancey = (p.GetY() - y); return Math.sqrt(Math.pow(distancex, 2) + Math.pow(distancey, 2)); } public String toString() { return("(" + x + ", " + y + ")"); } }
So is there any way to let java save the array in an excel file?
PS: I couldn't find a search function on this forum, so I don't know if this question has been asked already.
- 10-11-2009, 02:42 PM #2
Member
- Join Date
- Apr 2009
- Posts
- 54
- Rep Power
- 0
Why not save the array in a text file (myFile.txt) and then open that file in Excel?
-
Life is not the worst thing we have ... in a few minutes my coffee is ready.
- 10-11-2009, 03:27 PM #3
Member
- Join Date
- Oct 2009
- Location
- Rotterdam
- Posts
- 52
- Rep Power
- 0
- 10-11-2009, 03:43 PM #4
Member
- Join Date
- Apr 2009
- Posts
- 54
- Rep Power
- 0
Ok, you can use 'FileWriter' the google-link is here
filewriter java - Google Search-
Life is not the worst thing we have ... in a few minutes my coffee is ready.
-
And you want to do something much much more difficult -- trying to have java create an excel file? Let's have a dose of realism here.
Edit: Instead why don't you look into using System.out.printf to print out the results to either the command line or a text file all nice and formatted? This would be so much easier than trying to interface Java with Excel.Last edited by Fubarable; 10-11-2009 at 04:33 PM.
Similar Threads
-
How to create excel sheet?
By kishan in forum Advanced JavaReplies: 3Last Post: 07-13-2010, 01:15 PM -
How to Read Excel file??
By spalax in forum New To JavaReplies: 3Last Post: 08-15-2009, 05:06 AM -
upload excel file into database
By bhasker4 in forum IntroductionsReplies: 1Last Post: 07-13-2009, 09:13 PM -
How to read Excel file with java
By chetan-24 in forum New To JavaReplies: 5Last Post: 04-22-2009, 05:11 PM -
Not able to generate excel file locally
By wickedrahul9 in forum Advanced JavaReplies: 4Last Post: 10-23-2008, 11:17 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks