You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by veena pandit <v....@gmail.com> on 2009/10/26 20:38:13 UTC

POI question

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

Re: POI question

Posted by Bruno Girin <br...@gmail.com>.
2009/10/26 veena pandit <v....@gmail.com>:
> I am doing exactly what the sample code you are pointing to says to do.
> But it does not open up the xls file in the browser.  It opens an empty
> sheet.

Well, no it won't because the code you are writing is running on the
server and will therefore open the file on the server. If you want to
feed it to the browser, you need to write it out to the servlet
response's output stream.

So in practice, you need something like:

String path = "c://downloads//" + "test.xls";
response.setHeader("Content-disposition", "inline;filename="+path);
InputStream inp = new FileInputStream(path);
hssfWorkBook = new HSSFWorkbook(inp);
OutpurSteam out = res.getOutputStream();
wb.write(out);

where res is the HttpServletResponse passed to the servlet's doGet or
doPost method. You will also need to set the content type header to
the correct MIME type.

However, if the only thing you are trying to do is to stream an
existing Excel file to a browser without modification you don't need
POI for this, you just need to copy the content of the InputStream to
the OutputStream.

Bruno

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: POI question

Posted by Josh Micich <jo...@gmail.com>.
Hello Veena,

It's patently untenable to write on a POI mailing list:
> I am not trying to learn poi,  I need it urgently for work.

If you make a request for help with an open source project you should
do your best to:
 (a) - make sure you have a real, relevant problem
 (b) - make it clear exactly is going wrong


You have provided so few details as to what you are trying to achieve,
the code you have written so far, and the actual error you are
receiving that it is nearly impossible to help you.  It's quite
unusual to get this far (three users helping already) without any real
progress.  The problems that you are describing seem to have nothing
to do with POI.  It's not even clear if you need POI at all.  There
are heaps of examples on-line that show how to stream an Excel file
from a servlet.  Please find more relevant forums to post non-POI
related issues.


BTW - You have said that you are trying to "read and edit an existing
xls file".  This may not work as transparently as you hope.  As far as
I understand, once the workbook is opened in the web browser, it can
be edited but cannot be simply 'saved' back to the web server.  To
send the changes back to the server, the user must manually save the
file locally and then upload that file with a standard HTTP multipart
request.  Again, this issue is quite independent of POI.

regards,
Josh

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: POI question

Posted by veena pandit <v....@gmail.com>.
Bruno,

Sorry I think I tried to be clear but I still confused the issue.  My first
jsp page allows the user to select
a file.  The action in the backing bean of that file selection
component(which is a dropdown) redirects
to a servlet which serves the page.

Thanks,

Veena

On Tue, Oct 27, 2009 at 10:29 AM, Bruno Girin <br...@gmail.com> wrote:

> 2009/10/27 veena pandit <v....@gmail.com>:
> > Hi,
> >
> > 1.  That is exactly what I mean.  I have a jsf dynamic web project in
> > eclipse.  When I right click on the first web page and select run on
> Server,
> > it runs correctly and locates the correct file and opens it as a xls
> > document.
>
> OK
>
> >
> > 2.  In order to open the page in a browser, you have to deploy the
> project
> > as a war file to the webapps directory of tomcat, then point your browser
> to
> > the location of the page and this should run the application.  But here
> is
> > where I am getting a java.lang.RuntimeException FacesContext not found
> > exception.  I have posted to a jsf forum at javaranch.com
>
> Yes, that's how you would deploy it on Tomcat. If it doesn't work then
> it means that you web.xml or your faces-config.xml has a problem and
> works well in the embedded container in eclipse but doesn't work in
> Tomcat.
>
>
> >
> > 3. I dont need to modify the excel file.  I just clarified and it is open
> as
> > a read only document.  I am expecting the browser to open the file
> viewable
> > as an excel document handled by the poi(similar to when I run it from
> > eclipse).
>
> This is where you got us all confused and where I think you
> misunderstand what POI does. Opening the file in your browser has
> nothing to do with POI, it's done by the browser running Excel when it
> receives the file.
>
> From your description above, you don't need POI at all, you can just
> copy the content of your file input stream to your response output
> stream in your servlet and that is enough to send the file to the
> browser and have the browser open it. In fact, that would be a better
> solution because you would then send the file unmodified and you would
> be able to stream it too.
>
> And as David say, that part probably needs to be done in a separate
> servlet that runs beside the JSP/JSF application you have and is
> dedicated to serve binary files to the browser.
>
> Bruno
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

Re: POI question

Posted by Bruno Girin <br...@gmail.com>.
2009/10/27 veena pandit <v....@gmail.com>:
> Hi,
>
> 1.  That is exactly what I mean.  I have a jsf dynamic web project in
> eclipse.  When I right click on the first web page and select run on Server,
> it runs correctly and locates the correct file and opens it as a xls
> document.

OK

>
> 2.  In order to open the page in a browser, you have to deploy the project
> as a war file to the webapps directory of tomcat, then point your browser to
> the location of the page and this should run the application.  But here is
> where I am getting a java.lang.RuntimeException FacesContext not found
> exception.  I have posted to a jsf forum at javaranch.com

Yes, that's how you would deploy it on Tomcat. If it doesn't work then
it means that you web.xml or your faces-config.xml has a problem and
works well in the embedded container in eclipse but doesn't work in
Tomcat.


>
> 3. I dont need to modify the excel file.  I just clarified and it is open as
> a read only document.  I am expecting the browser to open the file viewable
> as an excel document handled by the poi(similar to when I run it from
> eclipse).

This is where you got us all confused and where I think you
misunderstand what POI does. Opening the file in your browser has
nothing to do with POI, it's done by the browser running Excel when it
receives the file.

>From your description above, you don't need POI at all, you can just
copy the content of your file input stream to your response output
stream in your servlet and that is enough to send the file to the
browser and have the browser open it. In fact, that would be a better
solution because you would then send the file unmodified and you would
be able to stream it too.

And as David say, that part probably needs to be done in a separate
servlet that runs beside the JSP/JSF application you have and is
dedicated to serve binary files to the browser.

Bruno

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: POI question

Posted by veena pandit <v....@gmail.com>.
David,

I tried so hard to be clear.  My first page is a jsp page.  I figured out
how to redirect to a servlet.  and within eclipse it works ok.
But when I deploy it as a war file it doesn't work.  I need to make it work
and I will also post to Sun forum.

Thanks,

Veena

On Tue, Oct 27, 2009 at 10:25 AM, David Fisher <df...@jmlafferty.com>wrote:

> You need to get help from the the JSF people in setting up a servlet.
>
> JSPs are meant to serve text formats only, Excel XLS is a binary format.
> You can get away with serving binary through a JSP in some servers, but you
> cannot in all of them. For instance I got away with serving PDF through a
> jsp in Tomcat in version 3.3 through version 4.1.29, but then it was no
> longer possible, and it was time to deploy a servlet.
>
> The people at javaranch ought to be able to help you, just make sure you
> tell them that it is a binary file format.
>
> I suggest that you take the time to carefully read everything sent to you,
> all the bits are there. Please make sure of your requirements, try to make
> your example simple and describe all of the requirements and tools. You'll
> get better help, learn more, and won't frustrate the four people willing to
> try to help you anyway.
>
> Regards,
> Dave
>
>
> On Oct 27, 2009, at 7:06 AM, veena pandit wrote:
>
> Hi,
>>
>> 1.  That is exactly what I mean.  I have a jsf dynamic web project in
>> eclipse.  When I right click on the first web page and select run on
>> Server,
>> it runs correctly and locates the correct file and opens it as a xls
>> document.
>>
>> 2.  In order to open the page in a browser, you have to deploy the project
>> as a war file to the webapps directory of tomcat, then point your browser
>> to
>> the location of the page and this should run the application.  But here is
>> where I am getting a java.lang.RuntimeException FacesContext not found
>> exception.  I have posted to a jsf forum at javaranch.com
>>
>> 3. I dont need to modify the excel file.  I just clarified and it is open
>> as
>> a read only document.  I am expecting the browser to open the file
>> viewable
>> as an excel document handled by the poi(similar to when I run it from
>> eclipse).
>>
>> Thanks,
>>
>> Veena
>>
>> On Tue, Oct 27, 2009 at 9:50 AM, Bruno Girin <br...@gmail.com>
>> wrote:
>>
>> 2009/10/27 veena pandit <v....@gmail.com>:
>>>
>>>> I don't think i will have to edit and save.  I need to check.
>>>> I think the files are read only.  But thanks to Bruno,
>>>> and this list.  I was able to open the file from within eclipse.
>>>>
>>>
>>> I'm not sure I understand what you mean by opening the file from
>>> within eclipse. If you mean that the code you have written in eclipse
>>> can now open the xls file inside your servlet, then great, there's
>>> progress.
>>>
>>> I can't seem to deploy it and open it in my browser yet.
>>>> Any suggestions on the deployment?
>>>>
>>>
>>> I am not sure I understand this correctly either. When you say that
>>> you want to deploy and open it in your browser, what are you actually
>>> attempting to do? Do you want to see the excel sheet as a web page,
>>> like GoogleDocs do or do you want the browser to receive the file and
>>> open it with Excel?
>>>
>>> I am getting a FacesContext not found
>>>> error.
>>>>
>>>
>>> Well, this means that your JSF configuration is incorrect. The problem
>>> is probably somewhere in your web.xml or faces-config.xml files.
>>> However, this has nothing to do with POI so this list is not the best
>>> place to ask that sort of questions. You'd be better off asking help
>>> for this specific problem on a JSF forum where you have people who can
>>> help better.
>>>
>>> It would help enormously if you could describe what you are trying to
>>> do. At the moment, the different bits of information I've gathered
>>> from your various emails tell me that you are writing a JSF
>>> application that runs in a servlet container and that needs to send
>>> Excel files to the user's browser. Is this correct? What I don't
>>> understand is:
>>> 1. do you need to modify the Excel file inside the servlet before
>>> sending it to the browser?
>>> 2. how do you expect the browser to handle the file?
>>>
>>> Bruno
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>>> For additional commands, e-mail: user-help@poi.apache.org
>>>
>>>
>>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

Re: POI question

Posted by David Fisher <df...@jmlafferty.com>.
You need to get help from the the JSF people in setting up a servlet.

JSPs are meant to serve text formats only, Excel XLS is a binary  
format. You can get away with serving binary through a JSP in some  
servers, but you cannot in all of them. For instance I got away with  
serving PDF through a jsp in Tomcat in version 3.3 through version  
4.1.29, but then it was no longer possible, and it was time to deploy  
a servlet.

The people at javaranch ought to be able to help you, just make sure  
you tell them that it is a binary file format.

I suggest that you take the time to carefully read everything sent to  
you, all the bits are there. Please make sure of your requirements,  
try to make your example simple and describe all of the requirements  
and tools. You'll get better help, learn more, and won't frustrate the  
four people willing to try to help you anyway.

Regards,
Dave

On Oct 27, 2009, at 7:06 AM, veena pandit wrote:

> Hi,
>
> 1.  That is exactly what I mean.  I have a jsf dynamic web project in
> eclipse.  When I right click on the first web page and select run on  
> Server,
> it runs correctly and locates the correct file and opens it as a xls
> document.
>
> 2.  In order to open the page in a browser, you have to deploy the  
> project
> as a war file to the webapps directory of tomcat, then point your  
> browser to
> the location of the page and this should run the application.  But  
> here is
> where I am getting a java.lang.RuntimeException FacesContext not found
> exception.  I have posted to a jsf forum at javaranch.com
>
> 3. I dont need to modify the excel file.  I just clarified and it is  
> open as
> a read only document.  I am expecting the browser to open the file  
> viewable
> as an excel document handled by the poi(similar to when I run it from
> eclipse).
>
> Thanks,
>
> Veena
>
> On Tue, Oct 27, 2009 at 9:50 AM, Bruno Girin <br...@gmail.com>  
> wrote:
>
>> 2009/10/27 veena pandit <v....@gmail.com>:
>>> I don't think i will have to edit and save.  I need to check.
>>> I think the files are read only.  But thanks to Bruno,
>>> and this list.  I was able to open the file from within eclipse.
>>
>> I'm not sure I understand what you mean by opening the file from
>> within eclipse. If you mean that the code you have written in eclipse
>> can now open the xls file inside your servlet, then great, there's
>> progress.
>>
>>> I can't seem to deploy it and open it in my browser yet.
>>> Any suggestions on the deployment?
>>
>> I am not sure I understand this correctly either. When you say that
>> you want to deploy and open it in your browser, what are you actually
>> attempting to do? Do you want to see the excel sheet as a web page,
>> like GoogleDocs do or do you want the browser to receive the file and
>> open it with Excel?
>>
>>> I am getting a FacesContext not found
>>> error.
>>
>> Well, this means that your JSF configuration is incorrect. The  
>> problem
>> is probably somewhere in your web.xml or faces-config.xml files.
>> However, this has nothing to do with POI so this list is not the best
>> place to ask that sort of questions. You'd be better off asking help
>> for this specific problem on a JSF forum where you have people who  
>> can
>> help better.
>>
>> It would help enormously if you could describe what you are trying to
>> do. At the moment, the different bits of information I've gathered
>> from your various emails tell me that you are writing a JSF
>> application that runs in a servlet container and that needs to send
>> Excel files to the user's browser. Is this correct? What I don't
>> understand is:
>> 1. do you need to modify the Excel file inside the servlet before
>> sending it to the browser?
>> 2. how do you expect the browser to handle the file?
>>
>> Bruno
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>> For additional commands, e-mail: user-help@poi.apache.org
>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: POI question

Posted by veena pandit <v....@gmail.com>.
Hi,

1.  That is exactly what I mean.  I have a jsf dynamic web project in
eclipse.  When I right click on the first web page and select run on Server,
it runs correctly and locates the correct file and opens it as a xls
document.

2.  In order to open the page in a browser, you have to deploy the project
as a war file to the webapps directory of tomcat, then point your browser to
the location of the page and this should run the application.  But here is
where I am getting a java.lang.RuntimeException FacesContext not found
exception.  I have posted to a jsf forum at javaranch.com

3. I dont need to modify the excel file.  I just clarified and it is open as
a read only document.  I am expecting the browser to open the file viewable
as an excel document handled by the poi(similar to when I run it from
eclipse).

Thanks,

Veena

On Tue, Oct 27, 2009 at 9:50 AM, Bruno Girin <br...@gmail.com> wrote:

> 2009/10/27 veena pandit <v....@gmail.com>:
> > I don't think i will have to edit and save.  I need to check.
> > I think the files are read only.  But thanks to Bruno,
> > and this list.  I was able to open the file from within eclipse.
>
> I'm not sure I understand what you mean by opening the file from
> within eclipse. If you mean that the code you have written in eclipse
> can now open the xls file inside your servlet, then great, there's
> progress.
>
> > I can't seem to deploy it and open it in my browser yet.
> > Any suggestions on the deployment?
>
> I am not sure I understand this correctly either. When you say that
> you want to deploy and open it in your browser, what are you actually
> attempting to do? Do you want to see the excel sheet as a web page,
> like GoogleDocs do or do you want the browser to receive the file and
> open it with Excel?
>
> > I am getting a FacesContext not found
> > error.
>
> Well, this means that your JSF configuration is incorrect. The problem
> is probably somewhere in your web.xml or faces-config.xml files.
> However, this has nothing to do with POI so this list is not the best
> place to ask that sort of questions. You'd be better off asking help
> for this specific problem on a JSF forum where you have people who can
> help better.
>
> It would help enormously if you could describe what you are trying to
> do. At the moment, the different bits of information I've gathered
> from your various emails tell me that you are writing a JSF
> application that runs in a servlet container and that needs to send
> Excel files to the user's browser. Is this correct? What I don't
> understand is:
> 1. do you need to modify the Excel file inside the servlet before
> sending it to the browser?
> 2. how do you expect the browser to handle the file?
>
> Bruno
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

Re: POI question

Posted by Bruno Girin <br...@gmail.com>.
2009/10/27 veena pandit <v....@gmail.com>:
> I don't think i will have to edit and save.  I need to check.
> I think the files are read only.  But thanks to Bruno,
> and this list.  I was able to open the file from within eclipse.

I'm not sure I understand what you mean by opening the file from
within eclipse. If you mean that the code you have written in eclipse
can now open the xls file inside your servlet, then great, there's
progress.

> I can't seem to deploy it and open it in my browser yet.
> Any suggestions on the deployment?

I am not sure I understand this correctly either. When you say that
you want to deploy and open it in your browser, what are you actually
attempting to do? Do you want to see the excel sheet as a web page,
like GoogleDocs do or do you want the browser to receive the file and
open it with Excel?

> I am getting a FacesContext not found
> error.

Well, this means that your JSF configuration is incorrect. The problem
is probably somewhere in your web.xml or faces-config.xml files.
However, this has nothing to do with POI so this list is not the best
place to ask that sort of questions. You'd be better off asking help
for this specific problem on a JSF forum where you have people who can
help better.

It would help enormously if you could describe what you are trying to
do. At the moment, the different bits of information I've gathered
from your various emails tell me that you are writing a JSF
application that runs in a servlet container and that needs to send
Excel files to the user's browser. Is this correct? What I don't
understand is:
1. do you need to modify the Excel file inside the servlet before
sending it to the browser?
2. how do you expect the browser to handle the file?

Bruno

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: POI question

Posted by veena pandit <v....@gmail.com>.
I don't think i will have to edit and save.  I need to check.
I think the files are read only.  But thanks to Bruno,
and this list.  I was able to open the file from within eclipse.
I can't seem to deploy it and open it in my browser yet.
Any suggestions on the deployment?  I am getting a FacesContext not found
error.

Thanks,

Veena
On Tue, Oct 27, 2009 at 9:13 AM, @lan Williamson <al...@alanwilliamson.org>wrote:

> __rolls eyes__
>
> Veena, please, learn how to interact with open source projects.
>
> The whole point of POI is to allow editing/saving of excel spreadsheets.
>  This is its whole point in life.
>
> I feel your Java understanding is letting you down here.  Play with POI in
> a simple Java class, and discover what you can do.   This is not an EXCEL
> replacement.  If you are hoping for this (which the more i read your posts
> the more i think it is) then you are barking up the wrong tree.
>
>
> veena pandit wrote:
>
>> Great!! Thanks for your help.  I guess editing and saving is not possible?
>>
>
>
>  ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

Re: POI question

Posted by "@lan Williamson" <al...@alanwilliamson.org>.
__rolls eyes__

Veena, please, learn how to interact with open source projects.

The whole point of POI is to allow editing/saving of excel spreadsheets. 
  This is its whole point in life.

I feel your Java understanding is letting you down here.  Play with POI 
in a simple Java class, and discover what you can do.   This is not an 
EXCEL replacement.  If you are hoping for this (which the more i read 
your posts the more i think it is) then you are barking up the wrong tree.

veena pandit wrote:
> Great!! Thanks for your help.  I guess editing and saving is not possible?


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: POI question

Posted by veena pandit <v....@gmail.com>.
Hi Bruno,

Great!! Thanks for your help.  I guess editing and saving is not possible?

Thanks again Bruno,

Veena

On Tue, Oct 27, 2009 at 6:01 AM, Bruno Girin <br...@gmail.com> wrote:

> > protected* *void* doGet(HttpServletRequest request, HttpServletResponse
> > response) *throws* ServletException, IOException {
>
> Your doGet method doesn't write to the response object and therefore
> is not sending anything to the web browser. Can you add the following
> line at the end of your method and see if it makes any difference
> please:
>
> wb.write(response.getOutputStream());
>
> Bruno
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

Re: POI question

Posted by Bruno Girin <br...@gmail.com>.
> protected* *void* doGet(HttpServletRequest request, HttpServletResponse
> response) *throws* ServletException, IOException {

Your doGet method doesn't write to the response object and therefore
is not sending anything to the web browser. Can you add the following
line at the end of your method and see if it makes any difference
please:

wb.write(response.getOutputStream());

Bruno

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: POI question

Posted by veena pandit <v....@gmail.com>.
Hi,

I am not trying to learn poi,  I need it urgently for work.
Someone please help. Here is the code in my servlet:
*

protected* *void* doGet(HttpServletRequest request, HttpServletResponse
response) *throws* ServletException, IOException {

// *TODO* Auto-generated method stub

*try* {

response.setContentType("application/vnd.ms-excel" );

// String filename = (String)request.getAttribute("selected");

HttpSession session = request.getSession();

String *filename* = (String)session.getAttribute("selected");

String path = "test.xls";

response.setHeader("Content-disposition", "inline;filename="+path);

// HSSFWorkbook wb = new HSSFWorkbook();

InputStream inp = *new* FileInputStream(path);

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

 Thanks in advance,



On Mon, Oct 26, 2009 at 4:16 PM, Kalpana <nk...@gmail.com> wrote:

> veena pandit <v.kris21 <at> gmail.com> writes:
>
> >
> > I am doing exactly what the sample code you are pointing to says to do.
> > But it does not open up the xls file in the browser.  It opens an empty
> > sheet.
> > I dont know if it is reading the file or not.
> >
> > THanks,
> >
> > Veena
> >
> > >
> I am not sure about opening an Xls file in a browser. Does test.xls have
> anything in it to be shown?
>
> If you are trying to learn how to work with xls files using POI, then I
> would
> suggest you try it out in standalone apps, and then get into opening them
> in
> browsers.
>
> Regards,
> Kalpana
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

Re: POI question

Posted by Kalpana <nk...@gmail.com>.
veena pandit <v.kris21 <at> gmail.com> writes:

> 
> I am doing exactly what the sample code you are pointing to says to do.
> But it does not open up the xls file in the browser.  It opens an empty
> sheet.
> I dont know if it is reading the file or not.
> 
> THanks,
> 
> Veena
> 
> > 
I am not sure about opening an Xls file in a browser. Does test.xls have 
anything in it to be shown?

If you are trying to learn how to work with xls files using POI, then I would 
suggest you try it out in standalone apps, and then get into opening them in 
browsers.

Regards,
Kalpana




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: POI question

Posted by veena pandit <v....@gmail.com>.
I am doing exactly what the sample code you are pointing to says to do.
But it does not open up the xls file in the browser.  It opens an empty
sheet.
I dont know if it is reading the file or not.

THanks,

Veena

On Mon, Oct 26, 2009 at 3:52 PM, Kalpana <nk...@gmail.com> wrote:

> 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: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

Re: POI question

Posted by Kalpana <nk...@gmail.com>.
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: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: POI question

Posted by veena pandit <v....@gmail.com>.
Hi,

I did try some of the examples at:

http://poi.apache.org/spreadsheet/examples.html

but they are not doing what I want to do. and that
is read and edit an existing xls file.

Thanks,

Veena

On Mon, Oct 26, 2009 at 3:46 PM, @lan Williamson <al...@alanwilliamson.org>wrote:

> what has log4j got to do with it?
>
> what are you expecting it to do?
>
> You are not giving us the full details, so there is nothing for us to
> really help you with.
>
> If there is an error, then a general java exception will be thrown and you
> can read that.
>
> i take it you have tried your code __outside__ of a servlet and created a
> simple Java class to get yourself familiar with POI.
>
>
>  ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

Re: POI question

Posted by "@lan Williamson" <al...@alanwilliamson.org>.
what has log4j got to do with it?

what are you expecting it to do?

You are not giving us the full details, so there is nothing for us to 
really help you with.

If there is an error, then a general java exception will be thrown and 
you can read that.

i take it you have tried your code __outside__ of a servlet and created 
a simple Java class to get yourself familiar with POI.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: POI question

Posted by veena pandit <v....@gmail.com>.
I dont have log4j.  There is nothing in the console.
Help!

Thanks,

Veena

On Mon, Oct 26, 2009 at 3:41 PM, @lan Williamson <al...@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@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

Re: POI question

Posted by "@lan Williamson" <al...@alanwilliamson.org>.
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@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org