Minecraft PC IP: play.cubecraft.net
Status
Not open for further replies.

NanoNet

Dedicated Member
May 23, 2014
1,044
357
158
IKEA
The tittle says it all(Well most of it xD).

My question is: Is there a way to read an Excel Spreadsheet from Java? I know you can do this with a .txt file, but I don't know of any way to read an Excel Spreadsheet. If it is not possible, perhaps is there a way to change the Excel Spreadsheet to a .txt file, within Java's code? It would mean a lot if someone answered, Thanks!
 

OrangeGE

Forum Expert
Jan 21, 2014
4,681
2,369
313
24
I assume it would be possible, but using the .csv end and stating which column you wish to read. I only know how to read sheets in Python so i'm not much help here, sorry!

@rubik_cube_man or @repository may be able to assist you. :)
 
  • Like
Reactions: NanoNet

alyphen

Well-Known Member
Jan 4, 2014
101
109
118
27
127.0.0.1
seventh-root.com
Yes, you can. There's a variety of different methods to do this depending on what you mean by "Excel Spreadsheet".
If you're just creating a table or something that opens in Excel, the easiest way is just to do it with csv and write your own parser, since csv are essentially text files.
If you're creating a slightly more advanced spreadsheet, I'd recommend using a library for OpenDocument spreadsheets, as these have better compatibility with LibreOffice and OpenOffice. One example is the Apache ODF toolkit.
If you're using an existing spreadsheet, or some Microsoft-specific functionality, you will want to look at Apache POI. It's an incredibly powerful library that allows you to manipulate Microsoft Excel spreadsheets (both OOXML and the old 2003 formats).
If you need any more help with this, I should be able to offer a little guidance.
 
  • Like
Reactions: NanoNet

NanoNet

Dedicated Member
May 23, 2014
1,044
357
158
IKEA
Thank you very much, I will look into this as soon as possible! :P I've been programming basic stuff for a while now, but I haven't done anything huge. xD
 

NanoNet

Dedicated Member
May 23, 2014
1,044
357
158
IKEA
Yes, you can. There's a variety of different methods to do this depending on what you mean by "Excel Spreadsheet".
If you're just creating a table or something that opens in Excel, the easiest way is just to do it with csv and write your own parser, since csv are essentially text files.
If you're creating a slightly more advanced spreadsheet, I'd recommend using a library for OpenDocument spreadsheets, as these have better compatibility with LibreOffice and OpenOffice. One example is the Apache ODF toolkit.
If you're using an existing spreadsheet, or some Microsoft-specific functionality, you will want to look at Apache POI. It's an incredibly powerful library that allows you to manipulate Microsoft Excel spreadsheets (both OOXML and the old 2003 formats).
If you need any more help with this, I should be able to offer a little guidance.
Re: With Microsoft Excel, I can save a spreadsheet as a .txt file, and choose what the separated value is (Such as Tab, single space, commas, etc.). Can I then read the file as a regular .txt file?
 

alyphen

Well-Known Member
Jan 4, 2014
101
109
118
27
127.0.0.1
seventh-root.com
Re: With Microsoft Excel, I can save a spreadsheet as a .txt file, and choose what the separated value is (Such as Tab, single space, commas, etc.). Can I then read the file as a regular .txt file?
Yes - you can write your own parser for it. When separating with commas, this is essentially a csv file ("Comma Separated Values")
Best practice would probably be to have a CSVFile class that takes a file into it's constructor (which it stores in a class variable/field). There would be a reload method that would parse the CSVFile and store the contents into a 2D array. The reload method is called in the constructor. Then finally, a getCellContents(int row, int col) method to retrieve the contents of any cell. You can then load the CSV file, retrieve any cell's contents, update them at a later time if necessary.
If you need write access too, add a setCell method which writes to the array, and a save method which saves back to the file. To have the file auto-update on change, the save method must be called at the end of the setCell method.
That's probably the easiest and cleanest way to do this.
 

NanoNet

Dedicated Member
May 23, 2014
1,044
357
158
IKEA
Thanks once again, I'm really trying to get an almost flawless understanding of writing to/reading files. You definitely helped me more than any YouTube video/google search!
 
Status
Not open for further replies.
Members Online

Team online

Latest profile posts

Xi1m wrote on Frontlane's profile.
genius idea frontland
IMG_8850.jpeg
GiGaGekkies wrote on xSchulzis's profile.
Congratulations...
GiGaGekkies wrote on WorriedSkate940's profile.
Congratulations!
GiGaGekkies wrote on Frontlane's profile.
I knew it! Congratulations
W streamer here: @SugaaKat
Top Bottom