Results 1 to 5 of 5
  1. #1
    Arnold is offline Member
    Join Date
    Oct 2009
    Location
    Rotterdam
    Posts
    52
    Rep Power
    0

    Post 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 {
    		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]);
    			}
    		}
    	}
    }
    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. #2
    pellebye is offline Member
    Join Date
    Apr 2009
    Posts
    54
    Rep Power
    0

    Default

    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.

  3. #3
    Arnold is offline Member
    Join Date
    Oct 2009
    Location
    Rotterdam
    Posts
    52
    Rep Power
    0

    Default

    Quote Originally Posted by pellebye View Post
    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. #4
    pellebye is offline Member
    Join Date
    Apr 2009
    Posts
    54
    Rep Power
    0

    Default

    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.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Arnold View Post
    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.

Similar Threads

  1. How to read Excel file with java
    By chetan-24 in forum New To Java
    Replies: 6
    Last Post: 09-13-2014, 01:43 PM
  2. How to create excel sheet?
    By kishan in forum Advanced Java
    Replies: 3
    Last Post: 07-13-2010, 02:15 PM
  3. How to Read Excel file??
    By spalax in forum New To Java
    Replies: 3
    Last Post: 08-15-2009, 06:06 AM
  4. upload excel file into database
    By bhasker4 in forum Introductions
    Replies: 1
    Last Post: 07-13-2009, 10:13 PM
  5. Not able to generate excel file locally
    By wickedrahul9 in forum Advanced Java
    Replies: 4
    Last Post: 10-23-2008, 12:17 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
  •