Java to read excel content specific code

  • 2020-04-01 02:19:14
  • OfStack

1. Need to download the jxl.jar package, I studied it, the code is as follows


package file;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.write.*;
import jxl.Sheet;
import jxl.Cell;
import jxl.Workbook;
public class excel {

public static void main(String[] args) throws BiffException, IOException {
// TODO Auto-generated method stub
Workbook book = Workbook.getWorkbook(new File("F://Center20130902update.xls"));
Sheet sheet=book.getSheet(0);
ArrayList list = new ArrayList();
for(int k=2;k<96;k++){ 
Map rowData = new HashMap();
for(int j=2;j<5;j++){
Cell cell = sheet.getCell(j,k);//Columns and rows
Cell keycell = sheet.getCell(j,1);
String key = keycell.getContents();
String Content = cell.getContents();
rowData.put(key, Content);
} 
list.add(rowData);
}
System.out.println(list);
book.close();
}
}


Related articles: