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/25 00:18:20 UTC

help with reading and editing a file with java

http://poi.apache.org/spreadsheet/how-to.html

If you navigate to this link there is another link on this page that is
dead.
It is supposed to take you to an example on how to read and edit an excel
file using java.
http://svn.apache.org/repos/asf/poi/trunk/src/java/org/apache/poi/hssf/dev/HSSF.java

Anyone know about this and can help me?

Thanks,

Sonia

Re: help with reading and editing a file with java

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

It also has some deprecated methods.

THanks,

Veena

On Mon, Oct 26, 2009 at 7:09 AM, Nick Burch <ni...@torchbox.com> wrote:

> On Sat, 24 Oct 2009, veena pandit wrote:
>
>> http://poi.apache.org/spreadsheet/how-to.html
>>
>> If you navigate to this link there is another link on this page that is
>> dead.
>> It is supposed to take you to an example on how to read and edit an excel
>> file using java.
>>
>> http://svn.apache.org/repos/asf/poi/trunk/src/java/org/apache/poi/hssf/dev/HSSF.java
>>
>
> It's new location is
>
> http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HSSFReadWrite.java
>
> I've updated the documentation, the corrected URL should be on the site in
> not too long
>
> Nick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

Re: help with reading and editing a file with java

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

For some reason it doesn't open up the existing file.  It opens up a new
excel document in the browser.
Can you tell me what I am doing wrong?

Here is the 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 = request.getParameter("filename");

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

// String filename = "test.xls";

HttpSession session = request.getSession();

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

String path = "c://downloads//" + filename;

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

// HSSFWorkbook wb = new HSSFWorkbook();

InputStream inp = *new* FileInputStream(path);

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

Workbook wb = (Workbook) WorkbookFactory.*create*(inp);

Sheet *sheet* = ( wb).getSheetAt(0);

 // create your workbook using Apache POI

wb.write(response.getOutputStream());

} *catch* (Exception e) {

e.printStackTrace();

}

}
Thanks,

Veena

On Mon, Oct 26, 2009 at 11:44 AM, David Fisher <df...@jmlafferty.com>wrote:

> (JSP) This works for a web server which follows the servlet spec. If this
> is your path then you will need to study how the WEB-INF directory works.
> You do not want to serve binary content directly from a jsp.
>
> (or Swing) - If you are talking about an application that creates an excel
> and the launches the file in Excel you will need to look into the Java
> Process class. Write your Excel file to the filesystem and then launch excel
> and the file.
>
> I hope this points you in the proper direction.
>
> Regards,
> Dave
>
>
> On Oct 26, 2009, at 7:51 AM, veena pandit wrote:
>
> Excellent idea! But could you tell me how the servlet fits into my JSF
>> project.
>> I have a jsp page that allows the user to select the file.  The selected
>> file is
>> an xls file and is pulled from the database.  I want to show the file as a
>> xls document in a browser(or swing).  So if I use your example, how would
>> I factor it in?  Not sure how to define the navigation rules.
>>
>> Thanks
>>
>> On Mon, Oct 26, 2009 at 8:50 AM, David Fisher <dfisher@jmlafferty.com
>> >wrote:
>>
>> In Apache Tomcat we have a servlet that does something like this:
>>>
>>> public class MyExcelServlet extends HttpServlet {
>>> public void doGet (HttpServletRequest request, HttpServletResponse
>>> response) throws ServletException, IOException {
>>> try {
>>>      response.setContentType("application/vnd.ms-excel" );
>>>      response.setHeader("Content-disposition",
>>> "inline;filename="+filename);
>>>      HSSFWorkbook wb = new HSSFWorkbook();
>>>      // create your workbook using Apache POI
>>>      wb.write(response.getOutputStream());
>>> } catch (Exception e) {
>>>
>>> }
>>> }
>>> }
>>>
>>> On Oct 26, 2009, at 6:34 AM, @lan Williamson wrote:
>>>
>>> That is the bit you are going to have to code up yourself
>>>
>>>>
>>>> The purpose of POI is to give you the low-level functions to which to
>>>> operate with an EXCEL file.
>>>>
>>>>
>>>>
>>>> veena pandit wrote:
>>>>
>>>> Hi,
>>>>>
>>>>> It looks like all the examples on the page here:
>>>>>
>>>>> http://poi.apache.org/spreadsheet/examples.html
>>>>>
>>>>> are examples that produce an excel file.  I need an example
>>>>> that opens the file as a swing application.or in the browser,
>>>>> Is there such an example?
>>>>>
>>>>>
>>>> ---------------------------------------------------------------------
>>>> 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
>>>
>>>
>>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

Re: help with reading and editing a file with java

Posted by veena pandit <v....@gmail.com>.
Great!  Actually I got the redirection to work by googling the solution.  It
opens an excel document in the browser.
Now I need to make if find an existing xls document.

Veena

On Mon, Oct 26, 2009 at 11:44 AM, David Fisher <df...@jmlafferty.com>wrote:

> (JSP) This works for a web server which follows the servlet spec. If this
> is your path then you will need to study how the WEB-INF directory works.
> You do not want to serve binary content directly from a jsp.
>
> (or Swing) - If you are talking about an application that creates an excel
> and the launches the file in Excel you will need to look into the Java
> Process class. Write your Excel file to the filesystem and then launch excel
> and the file.
>
> I hope this points you in the proper direction.
>
> Regards,
> Dave
>
>
> On Oct 26, 2009, at 7:51 AM, veena pandit wrote:
>
> Excellent idea! But could you tell me how the servlet fits into my JSF
>> project.
>> I have a jsp page that allows the user to select the file.  The selected
>> file is
>> an xls file and is pulled from the database.  I want to show the file as a
>> xls document in a browser(or swing).  So if I use your example, how would
>> I factor it in?  Not sure how to define the navigation rules.
>>
>> Thanks
>>
>> On Mon, Oct 26, 2009 at 8:50 AM, David Fisher <dfisher@jmlafferty.com
>> >wrote:
>>
>> In Apache Tomcat we have a servlet that does something like this:
>>>
>>> public class MyExcelServlet extends HttpServlet {
>>> public void doGet (HttpServletRequest request, HttpServletResponse
>>> response) throws ServletException, IOException {
>>> try {
>>>      response.setContentType("application/vnd.ms-excel" );
>>>      response.setHeader("Content-disposition",
>>> "inline;filename="+filename);
>>>      HSSFWorkbook wb = new HSSFWorkbook();
>>>      // create your workbook using Apache POI
>>>      wb.write(response.getOutputStream());
>>> } catch (Exception e) {
>>>
>>> }
>>> }
>>> }
>>>
>>> On Oct 26, 2009, at 6:34 AM, @lan Williamson wrote:
>>>
>>> That is the bit you are going to have to code up yourself
>>>
>>>>
>>>> The purpose of POI is to give you the low-level functions to which to
>>>> operate with an EXCEL file.
>>>>
>>>>
>>>>
>>>> veena pandit wrote:
>>>>
>>>> Hi,
>>>>>
>>>>> It looks like all the examples on the page here:
>>>>>
>>>>> http://poi.apache.org/spreadsheet/examples.html
>>>>>
>>>>> are examples that produce an excel file.  I need an example
>>>>> that opens the file as a swing application.or in the browser,
>>>>> Is there such an example?
>>>>>
>>>>>
>>>> ---------------------------------------------------------------------
>>>> 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
>>>
>>>
>>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

Re: help with reading and editing a file with java

Posted by David Fisher <df...@jmlafferty.com>.
(JSP) This works for a web server which follows the servlet spec. If  
this is your path then you will need to study how the WEB-INF  
directory works. You do not want to serve binary content directly from  
a jsp.

(or Swing) - If you are talking about an application that creates an  
excel and the launches the file in Excel you will need to look into  
the Java Process class. Write your Excel file to the filesystem and  
then launch excel and the file.

I hope this points you in the proper direction.

Regards,
Dave

On Oct 26, 2009, at 7:51 AM, veena pandit wrote:

> Excellent idea! But could you tell me how the servlet fits into my JSF
> project.
> I have a jsp page that allows the user to select the file.  The  
> selected
> file is
> an xls file and is pulled from the database.  I want to show the  
> file as a
> xls document in a browser(or swing).  So if I use your example, how  
> would
> I factor it in?  Not sure how to define the navigation rules.
>
> Thanks
>
> On Mon, Oct 26, 2009 at 8:50 AM, David Fisher  
> <df...@jmlafferty.com>wrote:
>
>> In Apache Tomcat we have a servlet that does something like this:
>>
>> public class MyExcelServlet extends HttpServlet {
>> public void doGet (HttpServletRequest request, HttpServletResponse
>> response) throws ServletException, IOException {
>> try {
>>       response.setContentType("application/vnd.ms-excel" );
>>       response.setHeader("Content-disposition",
>> "inline;filename="+filename);
>>       HSSFWorkbook wb = new HSSFWorkbook();
>>       // create your workbook using Apache POI
>>       wb.write(response.getOutputStream());
>> } catch (Exception e) {
>>
>> }
>> }
>> }
>>
>> On Oct 26, 2009, at 6:34 AM, @lan Williamson wrote:
>>
>> That is the bit you are going to have to code up yourself
>>>
>>> The purpose of POI is to give you the low-level functions to which  
>>> to
>>> operate with an EXCEL file.
>>>
>>>
>>>
>>> veena pandit wrote:
>>>
>>>> Hi,
>>>>
>>>> It looks like all the examples on the page here:
>>>>
>>>> http://poi.apache.org/spreadsheet/examples.html
>>>>
>>>> are examples that produce an excel file.  I need an example
>>>> that opens the file as a swing application.or in the browser,
>>>> Is there such an example?
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>


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


Re: help with reading and editing a file with java

Posted by veena pandit <v....@gmail.com>.
Excellent idea! But could you tell me how the servlet fits into my JSF
project.
I have a jsp page that allows the user to select the file.  The selected
file is
an xls file and is pulled from the database.  I want to show the file as a
xls document in a browser(or swing).  So if I use your example, how would
I factor it in?  Not sure how to define the navigation rules.

Thanks

On Mon, Oct 26, 2009 at 8:50 AM, David Fisher <df...@jmlafferty.com>wrote:

> In Apache Tomcat we have a servlet that does something like this:
>
> public class MyExcelServlet extends HttpServlet {
> public void doGet (HttpServletRequest request, HttpServletResponse
> response) throws ServletException, IOException {
> try {
>        response.setContentType("application/vnd.ms-excel" );
>        response.setHeader("Content-disposition",
> "inline;filename="+filename);
>        HSSFWorkbook wb = new HSSFWorkbook();
>        // create your workbook using Apache POI
>        wb.write(response.getOutputStream());
> } catch (Exception e) {
>
> }
> }
> }
>
> On Oct 26, 2009, at 6:34 AM, @lan Williamson wrote:
>
> That is the bit you are going to have to code up yourself
>>
>> The purpose of POI is to give you the low-level functions to which to
>> operate with an EXCEL file.
>>
>>
>>
>> veena pandit wrote:
>>
>>> Hi,
>>>
>>> It looks like all the examples on the page here:
>>>
>>> http://poi.apache.org/spreadsheet/examples.html
>>>
>>> are examples that produce an excel file.  I need an example
>>> that opens the file as a swing application.or in the browser,
>>> Is there such an example?
>>>
>>
>> ---------------------------------------------------------------------
>> 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: help with reading and editing a file with java

Posted by David Fisher <df...@jmlafferty.com>.
In Apache Tomcat we have a servlet that does something like this:

public class MyExcelServlet extends HttpServlet {
public void doGet (HttpServletRequest request, HttpServletResponse  
response) throws ServletException, IOException {
try {
	response.setContentType("application/vnd.ms-excel" );
	response.setHeader("Content-disposition", "inline;filename="+filename);
	HSSFWorkbook wb = new HSSFWorkbook();
	// create your workbook using Apache POI
	wb.write(response.getOutputStream());
} catch (Exception e) {
}
}
}

On Oct 26, 2009, at 6:34 AM, @lan Williamson wrote:

> That is the bit you are going to have to code up yourself
>
> The purpose of POI is to give you the low-level functions to which  
> to operate with an EXCEL file.
>
>
>
> veena pandit wrote:
>> Hi,
>>
>> It looks like all the examples on the page here:
>>
>> http://poi.apache.org/spreadsheet/examples.html
>>
>> are examples that produce an excel file.  I need an example
>> that opens the file as a swing application.or in the browser,
>> Is there such an example?
>
> ---------------------------------------------------------------------
> 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: help with reading and editing a file with java

Posted by "@lan Williamson" <al...@alanwilliamson.org>.
That is the bit you are going to have to code up yourself

The purpose of POI is to give you the low-level functions to which to 
operate with an EXCEL file.



veena pandit wrote:
> Hi,
>
> It looks like all the examples on the page here:
>
> http://poi.apache.org/spreadsheet/examples.html
>
> are examples that produce an excel file.  I need an example
> that opens the file as a swing application.or in the browser,
> Is there such an example?

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


Re: help with reading and editing a file with java

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

It looks like all the examples on the page here:

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

are examples that produce an excel file.  I need an example
that opens the file as a swing application.or in the browser,
Is there such an example?

Thanks,

Veena




On Mon, Oct 26, 2009 at 7:09 AM, Nick Burch <ni...@torchbox.com> wrote:

> On Sat, 24 Oct 2009, veena pandit wrote:
>
>> http://poi.apache.org/spreadsheet/how-to.html
>>
>> If you navigate to this link there is another link on this page that is
>> dead.
>> It is supposed to take you to an example on how to read and edit an excel
>> file using java.
>>
>> http://svn.apache.org/repos/asf/poi/trunk/src/java/org/apache/poi/hssf/dev/HSSF.java
>>
>
> It's new location is
>
> http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HSSFReadWrite.java
>
> I've updated the documentation, the corrected URL should be on the site in
> not too long
>
> Nick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

Re: help with reading and editing a file with java

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

I am getting errors in Eclipse for this file.  Please tell me how to fix it.
Eclipse gives me errors for HSSF constructor and the usage of HSSF.
I have imported the poi-3.5-FINAL libraries.

Thanks,

Veena

On Mon, Oct 26, 2009 at 7:09 AM, Nick Burch <ni...@torchbox.com> wrote:

> On Sat, 24 Oct 2009, veena pandit wrote:
>
>> http://poi.apache.org/spreadsheet/how-to.html
>>
>> If you navigate to this link there is another link on this page that is
>> dead.
>> It is supposed to take you to an example on how to read and edit an excel
>> file using java.
>>
>> http://svn.apache.org/repos/asf/poi/trunk/src/java/org/apache/poi/hssf/dev/HSSF.java
>>
>
> It's new location is
>
> http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HSSFReadWrite.java
>
> I've updated the documentation, the corrected URL should be on the site in
> not too long
>
> Nick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

Re: help with reading and editing a file with java

Posted by Nick Burch <ni...@torchbox.com>.
On Sat, 24 Oct 2009, veena pandit wrote:
> http://poi.apache.org/spreadsheet/how-to.html
>
> If you navigate to this link there is another link on this page that is
> dead.
> It is supposed to take you to an example on how to read and edit an excel
> file using java.
> http://svn.apache.org/repos/asf/poi/trunk/src/java/org/apache/poi/hssf/dev/HSSF.java

It's new location is
http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HSSFReadWrite.java

I've updated the documentation, the corrected URL should be on the site in 
not too long

Nick

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