Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Java and Excel

JilVWJilVW Member Posts: 2
Hi,

I am trying to read an Excel file.
I followed this tutorial: http://viralpatel.net/blogs/java-read-write-excel-file-apache-poi/

But I am getting following errors:
Row cannot be resolved to a type
Iterator cannot be resolved to a type
Cell cannot be resolved to a type
File cannot be resolved to a type

I used the following code:


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;


import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class TestExcel
{

public static void main(String[] args)
{
try
{
FileInputStream fileInputStream = new FileInputStream(new File("D:\Data\Stage_Jil\Eclipse-programmeren\Excel-bestanden\Test.xls"));
HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream);
HSSFSheet worksheet = workbook.getSheetAt(0);
Iterator rowIterator = worksheet.iterator();
while(rowIterator.hasNext())
{
Row row = rowIterator.next();
Iterator cellIterator = row.cellIterator();
while (cellIterator.hasNext())
{
Cell cell = cellIterator.next();
switch(cell.getCellType())
{
case Cell.CELL_TYPE_BOOLEAN:
System.out.print(cell.getBooleanCellValue() + " ");
break;
case Cell.CELL_TYPE_NUMERIC:
System.out.print(cell.getNumericCellValue() + " ");
break;
case Cell.CELL_TYPE_STRING:
System.out.print(cell.getStringCellValue() + " ");
break;
}
}
System.out.println("");
}
fileInputStream.close();
FileOutputStream out = new FileOutputStream(new File("D:\Data\Stage_Jil\Eclipse-programmeren\Excel-bestanden\Test.xls"));
workbook.write(out);
out.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}


}

}
Sign In or Register to comment.