Handling Excel file in Java

2019-08-31 17:43发布

I have a Excel file that I have to read the file and go line by line and check the first column. Here is an example of the column headers

ISBN#13 Run Date    Title   Author  Type

So I have to check each ISBN#13 and determine if it is an isbn#13, format it and write the whole line to a file. Then take all the ones that are not ISBN#13 and write them to a file.

So the question is how do I check the column "ISBN#13" and how do I write each row to a file. It would be another excel file.

标签: java excel
2条回答
何必那么认真
2楼-- · 2019-08-31 18:28

There is also xslx4j (part of docx4j) if you are working with xlsx only (ie not the legacy binary .xls) and prefer to use jaxb

查看更多
放我归山
3楼-- · 2019-08-31 18:31

The Apache poi (Poor Obfuscation Implementation) project is made for reading from and writing to Excel files in Java:

http://poi.apache.org/

Code example:

import java.io.*;
import org.apache.poi.xssf.usermodel.*;
public class CreateWorkBook 
{
   public static void main(String[] args)throws Exception 
   {
      //Create Blank workbook
      XSSFWorkbook workbook = new XSSFWorkbook(); 
      //Create file system using specific name
      FileOutputStream out = new FileOutputStream(
      new File("createworkbook.xlsx"));
      //write operation workbook using file out object 
      workbook.write(out);
      out.close();
      System.out.println("createworkbook.xlsx written successfully");
   }
}
查看更多
登录 后发表回答