Java y Excel
Hola a todos, ¿alguien sabe como puedo leer mas de una hoja de un archivo de Excel?, estoy usando el API HSSF de Jakarta POI.
Saludos
Gracias de antemano
Saludos
Gracias de antemano
public class Read2 {
/**
* @param args
* @throws IOException
* @throws FileNotFoundException
*/
public static void main(String[] args) throws FileNotFoundException, IOException {
File excelFile = new File("c:\test.xls");
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(excelFile));
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.createSheet("Sheet1");
HSSFRow row = sheet.getRow(1);
HSSFFont hssfFont = wb.createFont();
hssfFont.setFontName("Times New Roman");
hssfFont.setColor(HSSFColor.BLUE.index);
hssfFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
HSSFCellStyle style = wb.createCellStyle();
style.setFont(hssfFont);
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
style.setFillForegroundColor(HSSFColor.AQUA.index);
row.getCell((short)0).setCellStyle(style);
FileOutputStream fileOut = new FileOutputStream(excelFile);
wb.write(fileOut);
fileOut.close();
}
}
/**
* @param args
* @throws IOException
* @throws FileNotFoundException
*/
public static void main(String[] args) throws FileNotFoundException, IOException {
File excelFile = new File("c:\test.xls");
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(excelFile));
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.createSheet("Sheet1");
HSSFRow row = sheet.getRow(1);
HSSFFont hssfFont = wb.createFont();
hssfFont.setFontName("Times New Roman");
hssfFont.setColor(HSSFColor.BLUE.index);
hssfFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
HSSFCellStyle style = wb.createCellStyle();
style.setFont(hssfFont);
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
style.setFillForegroundColor(HSSFColor.AQUA.index);
row.getCell((short)0).setCellStyle(style);
FileOutputStream fileOut = new FileOutputStream(excelFile);
wb.write(fileOut);
fileOut.close();
}
}