0

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

skaffman
  • 398,947
  • 96
  • 818
  • 769
user618111
  • 439
  • 5
  • 15
  • 27

4 Answers4

1

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).

Justin Niessner
  • 242,243
  • 40
  • 408
  • 536
1
import java.io.IOException;

class ExcelStarter {
    public static void main(String args[]) throws IOException
   {
      Runtime.getRuntime().exec("cmd /c start excel.exe _pathtoexcelfile_");
   }
}
Ritch Melton
  • 11,498
  • 4
  • 41
  • 54
0

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.

Martijn Courteaux
  • 67,591
  • 47
  • 198
  • 287
0

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

Community
  • 1
  • 1
rajah9
  • 11,645
  • 5
  • 44
  • 57