You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by AlyssaK <al...@hotmail.com> on 2009/05/04 08:32:30 UTC

How to save the Excel file to file system

Hi everyone,

I was just wondering if i can use POI to save a copy of the Excel file that
i am reading on the file system?  I've looked through the API only found
references to creating new Excel files.  If you have a suggestion how i
would go about this please post a response. Thanks.


I am using the following method to open the Excel Spreadsheet:

public static void parseFileSetup(){
try{
// open the Excel Spreadsheet
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filename));
				
// check if the file was found
if (fs==null){
  System.out.println("fs is null");
}
wb = new HSSFWorkbook(fs);
}catch ( IOException ex ) {
     ex.printStackTrace();
}
}


Eventually users will be uploading files so I need to save it.

-- 
View this message in context: http://www.nabble.com/How-to-save-the-Excel-file-to-file-system-tp23363786p23363786.html
Sent from the POI - User mailing list archive at Nabble.com.


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


Re: How to save the Excel file to file system

Posted by AlyssaK <al...@hotmail.com>.
I'm developing a web app, so using an upload file control i want to save a
copy on the filesystem to be retrieved later on in addition to parsing that
file to upload the data to the database.

I will look into your post thanks for responding!

MSB wrote:
> 
> Can I just make sure that I understand what you want to accomplish please?
> Are you asking how to create a copy of an existing Excel file? You do not
> want to process the file at all just make a copy of it?
> 
> If that is correct, then you do not need to use POI at all, core Java will
> suffice. You need to open an input stream connected to the existing file
> and an output stream connected to the 'new' copy file. Next, simply write
> a loop that reads data from the input stream and writes it to the output
> stream. The loop will terminate once all data has been read from the input
> file and at that time you can flush the output stream, and close both
> input and output stream. If it were me, I would use buffered input and
> output streams to ease the burden on the IO system but that is by no means
> compulsory.
> 
> 
> 
> AlyssaK wrote:
>> 
>> Hi everyone,
>> 
>> I was just wondering if i can use POI to save a copy of the Excel file
>> that i am reading on the file system?  I've looked through the API only
>> found references to creating new Excel files.  If you have a suggestion
>> how i would go about this please post a response. Thanks.
>> 
>> 
>> I am using the following method to open the Excel Spreadsheet:
>> 
>> public static void parseFileSetup(){
>> try{
>> // open the Excel Spreadsheet
>> POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filename));
>> 				
>> // check if the file was found
>> if (fs==null){
>>   System.out.println("fs is null");
>> }
>> wb = new HSSFWorkbook(fs);
>> }catch ( IOException ex ) {
>>      ex.printStackTrace();
>> }
>> }
>> 
>> 
>> Eventually users will be uploading files so I need to save it.
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-save-the-Excel-file-to-file-system-tp23363786p23364527.html
Sent from the POI - User mailing list archive at Nabble.com.


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


Re: How to save the Excel file to file system

Posted by MSB <ma...@tiscali.co.uk>.
Can I just make sure that I understand what you want to accomplish please?
Are you asking how to create a copy of an existing Excel file? You do not
want to process the file at all just make a copy of it?

If that is correct, then you do not need to use POI at all, core Java will
suffice. You need to open an input stream connected to the existing file and
an output stream connected to the 'new' copy file. Next, simply write a loop
that reads data from the input stream and writes it to the output stream.
The loop will terminate once all data has been read from the input file and
at that time you can flush the output stream, and close both input and
output stream. If it were me, I would use buffered input and output streams
to ease the burden on the IO system but that is by no means compulsory.



AlyssaK wrote:
> 
> Hi everyone,
> 
> I was just wondering if i can use POI to save a copy of the Excel file
> that i am reading on the file system?  I've looked through the API only
> found references to creating new Excel files.  If you have a suggestion
> how i would go about this please post a response. Thanks.
> 
> 
> I am using the following method to open the Excel Spreadsheet:
> 
> public static void parseFileSetup(){
> try{
> // open the Excel Spreadsheet
> POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filename));
> 				
> // check if the file was found
> if (fs==null){
>   System.out.println("fs is null");
> }
> wb = new HSSFWorkbook(fs);
> }catch ( IOException ex ) {
>      ex.printStackTrace();
> }
> }
> 
> 
> Eventually users will be uploading files so I need to save it.
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-save-the-Excel-file-to-file-system-tp23363786p23364130.html
Sent from the POI - User mailing list archive at Nabble.com.


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


Re: How to save the Excel file to file system

Posted by MSB <ma...@tiscali.co.uk>.
...............and I should have said that yes, you can use HSSF/XSSF to
create a copy of the file. There is a method called write() defined on the
HSSFWorkbook class that could be used to create a copy of the file if you
are dealing with a binary .xls file. Further, there is a writeFileSystem()
method defined on the POIFSFileSystem class that you might be able to use to
create a copy of the file though I have never tried this myself. You would
simply pass an output stream to either and save the file you have opened
away under a new name and/or to a different location.

My only concern is that calling one of the write methods will also close the
streams for you and that this could cause problems if you wished to process
the original file after creating the copy. Having said this, I do not know
whether this is the case.


AlyssaK wrote:
> 
> Hi everyone,
> 
> I was just wondering if i can use POI to save a copy of the Excel file
> that i am reading on the file system?  I've looked through the API only
> found references to creating new Excel files.  If you have a suggestion
> how i would go about this please post a response. Thanks.
> 
> 
> I am using the following method to open the Excel Spreadsheet:
> 
> public static void parseFileSetup(){
> try{
> // open the Excel Spreadsheet
> POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filename));
> 				
> // check if the file was found
> if (fs==null){
>   System.out.println("fs is null");
> }
> wb = new HSSFWorkbook(fs);
> }catch ( IOException ex ) {
>      ex.printStackTrace();
> }
> }
> 
> 
> Eventually users will be uploading files so I need to save it.
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-save-the-Excel-file-to-file-system-tp23363786p23364267.html
Sent from the POI - User mailing list archive at Nabble.com.


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