user618111
user618111

Reputation: 439

Is there any way to import a .txt file in Excel using java?

i want to know if it's possible to import a text file in excel through java code. I know that we can use directly Excel and open a text file. But for me i want to do it with java because i have a java program that create a text file everyday and after i want to open it with excel automatically.

I don't want to loose my time to open Excel, then click import , then choose file, then... is it possible to do fastly with java?

Thank you

Upvotes: 0

Views: 3362

Answers (4)

rajah9
rajah9

Reputation: 12329

I have used Apache POI and their HSSF. It has a Java API with which to read Excel files.

If it is a CSV (Comma Separate Value) file, you may also want to see this question Can you recommend a java library for reading and possibly writing csv files

Upvotes: 0

Martijn Courteaux
Martijn Courteaux

Reputation: 68847

Yes, it is possible. You can parse your text file and put the data in a worksheet using the Apache XSSF library for xlsx. And then save it. 10 minutes of research should be sufficient to find what you need.

Upvotes: 0

Ritch Melton
Ritch Melton

Reputation: 11598

import java.io.IOException;

class ExcelStarter {
    public static void main(String args[]) throws IOException
   {
      Runtime.getRuntime().exec("cmd /c start excel.exe _pathtoexcelfile_");
   }
}

Upvotes: 1

Justin Niessner
Justin Niessner

Reputation: 245399

I think the easiest solution here would be to have your Java code create a Comma Seperated Value (CSV) file. They are easy to create and easy for Excel to open (no extra clicks required).

Upvotes: 1

Related Questions