ODCB-EXCEL

ODCB-EXCEL

View Answers

August 10, 2009 at 12:18 PM

Hi Friend,

Do you want to extract the data of the excel file that has been stored into the database or you simply want to extract the data of excel file?

Thanks


August 10, 2009 at 12:40 PM

Hello,

i simply want to extract data from excel file.
thank you very much.

SPX

August 19, 2009 at 2:52 PM

Hi Friend,

Try the following code:

import java.io.*;
import org.apache.poi.hpsf.*;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

public class ReadCSV{
public static void main(String[] args) {
try {
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("C:\\excelFile.xls"));
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row;
HSSFCell cell;
int counter=0;

int rows;
rows = sheet.getPhysicalNumberOfRows();
int cols = 0;
int tmp = 0;

for(int i = 0; i < 10 || i < rows; i++) {
row = sheet.getRow(i);
if(row != null) {
tmp = sheet.getRow(i).getPhysicalNumberOfCells();
if(tmp > cols) cols = tmp;
}

}
System.out.println("CSV File Data:");
for(int r = 0; r < rows; r++) {
row = sheet.getRow(r);
if(row != null) {
for(int c = 0; c < cols; c++) {
cell = row.getCell((short)c);
if(cell != null) {
System.out.println(cell+" ");
}
}
}
}
} catch(Exception ioe) {
ioe.printStackTrace();
}
}
}

Thanks









Related Tutorials/Questions & Answers:
ODCB-EXCEL - Java Beginners
ODCB-EXCEL  Hi, i would like to extract data from an excel file. my excel file name is: TEST.xls the worksheet name is : qas i have configure...: "java.sql.SQLException: [Microsoft][Pilote ODBC Excel] Not enough parameters 1

Ads