开发者

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 m开发者_开发知识库y time to open Excel, then click import , then choose file, then... is it possible to do fastly with java?

Thank you


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


import java.io.IOException;

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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜