2018年5月11日 星期五

[Java] Using POI Read Excel Files

https://poi.apache.org/download.html

public class ExcelUtil {

private static final String PATH = "C:\\Users\\bonnie\\Desktop\\";

public static void main(String[] args)
{
try
{
run();
}
catch(Exception e)
{
e.printStackTrace();
}
}

public static void run() throws Exception
{
// if the excel file does not have password, skip the 2nd parameter
Workbook wb = WorkbookFactory.create(
new FileInputStream(PATH + "a - password.xlsx"), "1234");
Sheet sheet = wb.getSheetAt(0);
Row row;
Cell cell;
for(int r = 0;r<10;r++)
{
row = sheet.getRow(r);
for(int c = 0;c<3;c++)
{
cell = row.getCell(c);
System.out.print(cell.getStringCellValue()+", ");
}
System.out.println();
}

}
}


沒有留言:

張貼留言