# Thread: How do you create an excel file?

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:
Java Code:
```import java.io.*;
class TestDistance {
public static void main(String[] args) throws IOException {
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):");
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]);
}
}
}
}```
The Point class:
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 + ")");
}
}```
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.

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.

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?

3. Member
Join Date
Oct 2009
Location
Rotterdam
Posts
52
Rep Power
0
Originally Posted by pellebye
Why not save the array in a text file (myFile.txt) and then open that file in Excel?
You don't understand. I don't know anything about saving files with java, not even a simple text file.

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

5. Originally Posted by Arnold
You don't understand. I don't know anything about saving files with java, not even a simple text file.
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 05:33 PM.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•