Java Excel Csv File
First Convert the excel file into the .csv file and then read through
public static ArrayList<CsvBean> setUpMakeAndModel(String storeLocation) {
System.out.println("Updating the bean list");
beanList=new ArrayList<CsvBean>();
try {
File file = new File("/..localtion to the file/device.csv");
BufferedReader bufRdr = new BufferedReader(new FileReader(file));
String line = null;
while ((line = bufRdr.readLine()) != null) {
CsvBean cb = new CsvBean();
int col=0;
String[] rowContents=new String[9];
StringTokenizer st = new StringTokenizer(line, ",");
while (st.hasMoreTokens()) {
rowContents[col] = st.nextToken();
col++;
if(col==9){
break;
}
}
cb.iD=rowContents[0]==null?"":rowContents[0];
cb.brand=rowContents[1]==null?"":rowContents[1];
cb.equipmentMaster=rowContents[1]==null?"":rowContents[2];
cb.make=rowContents[3]==null?"":rowContents[3];
cb.model=rowContents[4]==null?"":rowContents[4];
cb.image=rowContents[5]==null?"":rowContents[5];
cb.productID=rowContents[6]==null?"":rowContents[6];
cb.articleID=rowContents[7]==null?"":rowContents[7];
cb.url=rowContents[8]==null?"":rowContents[8];
beanList.add(cb);
}
bufRdr.close();
} catch (Exception e) {
System.out.println("Location of the device list not recognized");
return null;
}
return beanList;
First Convert the excel file into the .csv file and then read through
public static ArrayList<CsvBean> setUpMakeAndModel(String storeLocation) {
System.out.println("Updating the bean list");
beanList=new ArrayList<CsvBean>();
try {
File file = new File("/..localtion to the file/device.csv");
BufferedReader bufRdr = new BufferedReader(new FileReader(file));
String line = null;
while ((line = bufRdr.readLine()) != null) {
CsvBean cb = new CsvBean();
int col=0;
String[] rowContents=new String[9];
StringTokenizer st = new StringTokenizer(line, ",");
while (st.hasMoreTokens()) {
rowContents[col] = st.nextToken();
col++;
if(col==9){
break;
}
}
cb.iD=rowContents[0]==null?"":rowContents[0];
cb.brand=rowContents[1]==null?"":rowContents[1];
cb.equipmentMaster=rowContents[1]==null?"":rowContents[2];
cb.make=rowContents[3]==null?"":rowContents[3];
cb.model=rowContents[4]==null?"":rowContents[4];
cb.image=rowContents[5]==null?"":rowContents[5];
cb.productID=rowContents[6]==null?"":rowContents[6];
cb.articleID=rowContents[7]==null?"":rowContents[7];
cb.url=rowContents[8]==null?"":rowContents[8];
beanList.add(cb);
}
bufRdr.close();
} catch (Exception e) {
System.out.println("Location of the device list not recognized");
return null;
}
return beanList;
No comments:
Post a Comment