Create Excel file in Java

前端 未结 10 669
予麋鹿
予麋鹿 2020-12-02 15:23

I want to create an Excel file and write data just like writing a text file with Java. I tried to change file extension from .txt to .xls. But I wa

相关标签:
10条回答
  • 2020-12-02 16:04

    Changing the extension of a file does not in any way change its contents. The extension is just a label.

    If you want to work with Excel spreadsheets using Java, read up on the Apache POI library.

    0 讨论(0)
  • 2020-12-02 16:07

    I used also JXLS: it receives the data as a Map and a template EXCEL with the correct syntax and return the file correctly populated. The data in every cell must be a JavaBean with visibility public.

    It not worws if you must insert data in more than 1 sheet: in this case I used POI.

    0 讨论(0)
  • 2020-12-02 16:08

    I've created an API to create an Excel file more easier.

    Create Excel - Creating Excel from Template

    Just set the required values upon instantiation then invoke execute(), it will be created based on your desired output directory.

    But before you use this, you must have an Excel Template which will be use as a template of the newly created Excel file.

    Also, you need Apache POI in your project's class path.

    0 讨论(0)
  • 2020-12-02 16:09

    To create a spreadsheet and format a cell using POI, see the Working with Fonts example, and use:

    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    

    POI works very well. There are some things you can't do (e.g. create VBA macros), but it'll read/write spreadsheets with macros, so you can create a suitable template sheet, read it and manipulate it with POI, and then write it out.

    0 讨论(0)
提交回复
热议问题