veena pandit <v.kris21 <at> gmail.com> writes:

> 
> I dont have log4j.  There is nothing in the console.
> Help!
> 
> Thanks,
> 
> Veena
> 
> On Mon, Oct 26, 2009 at 3:41 PM, @lan Williamson <alan <at> 
alanwilliamson.org>wrote:
> 
> > what is the exception?
> >
> > the clue is usually in the exception message
> >
> >
> > veena pandit wrote:
> >
> >> Can someone tell me why this doesn;t work?  I am trying to open an
> >> existing
> >> file.
> >>
> >>
> >> String path = "c://downloads//" + "test.xls";
> >>
> >> response.setHeader("Content-disposition", "inline;filename="+path);
> >>
> >> // HSSFWorkbook wb = new HSSFWorkbook();
> >>
> >> InputStream inp = *new* FileInputStream(path);
> >>
> >> hssfWorkBook = *new* HSSFWorkbook(inp);
> >>
> >> Should this not open an existing xls file?
> >>
> >>
> >>
> >> Thanks,
> >>
> >>
> >>
> >> Veena
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe <at> poi.apache.org
> > For additional commands, e-mail: user-help <at> poi.apache.org
> >
> >
> 

Hi Veena,

There are some good examples at
http://poi.apache.org/spreadsheet/quick-guide.html#ReadWriteWorkbook

InputStream inp = new FileInputStream("workbook.xls");
    //InputStream inp = new FileInputStream("workbook.xlsx");

    Workbook wb = WorkbookFactory.create(inp);
    Sheet sheet = wb.getSheetAt(0);
    Row row = sheet.getRow(2);
    Cell cell = row.getCell(3);
    if (cell == null)
        cell = row.createCell(3);
    cell.setCellType(Cell.CELL_TYPE_STRING);
    cell.setCellValue("a test");

    // Write the output to a file
    FileOutputStream fileOut = new FileOutputStream("workbook.xls");
    wb.write(fileOut);
    fileOut.close();


I have pasted the read and writing an existing book example here.
You don't need log4j for outputting simple exceptions. You can do it yourself 
by catching the appropriate exception type in the catch block, and output the 
exception.getMessaage
() result.  Instead of writing catch(Exception oExp), try catchin the spe 
cific exception type like catch(IOException oExp) etc. To know what kind of 
exceptions are thrown, read the javadoc of the methods you are using or simply 
see the source code of those classes.


Regards,
Kalpana


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to