//FunctionRead data from Excel
//AuthorATGC
//Date of compilationOct 29,2004
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.hssf.record.*;
import org.apache.poi.hssf.model.*;
import org.apache.poi.hssf.util.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
import java.io.FileInputStream;
public class xls2table
{
public static String fileToBeRead="e://test.xls";
public static void main(String argv[])
{
try
{
HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(fileToBeRead));
HSSFSheet sheet = workbook.getSheet("Sheet1");
int rows = sheet.getPhysicalNumberOfRows();
for (int r = 0; r < rows; r++)
{
HSSFRow row = sheet.getRow(r);
if (row != null)
{
int cells = row.getPhysicalNumberOfCells();
String value = "";
System.out.println(cells);
for (short c = 0; c < cells; c++)
{
HSSFCell cell = row.getCell(c);
if (cell != null)
{
switch (cell.getCellType())
{
case HSSFCell.CELL_TYPE_FORMULA :
//strCell = String.valueOf(aCell.getNumericCellValue());
//returnstr+=strCell+" ";
break;
case HSSFCell.CELL_TYPE_NUMERIC:
value += (long)cell.getNumericCellValue()+"\t";
break;
case HSSFCell.CELL_TYPE_STRING:
value += cell.getStringCellValue()+"\t";
break;
case HSSFCell.CELL_TYPE_BLANK://blank
//strCell = aCell.getStringCellValue();
//returnstr+=strCell+" ";
break;
default:
value +="\t";
}
}
}
//下面可以将查找到的行内容用SQL语句INSERT到oracle
System.out.println(value);
//
}
}
}catch(Exception e)
{System.out.println(e);}
}
}
阅读(1918) | 评论(0) | 转发(0) |