You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Jani Gracnar <ja...@gmail.com> on 2009/05/28 10:33:25 UTC

Create object if Excel is already open

Hi,

Is it possible to create object of excel application which is already open
and the file is not saved as file on disk (the state after excel is just
started - no file name).

Thanx,

Jani
-- 
View this message in context: http://www.nabble.com/Create-object-if-Excel-is-already-open-tp23757513p23757513.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: Create object if Excel is already open

Posted by MSB <ma...@tiscali.co.uk>.
Now I understand what you are after.

The answer is that you cannot use POI in this manner I am afraid. All you
can use POI for is to create a file that can then be opened in Excel; it is
not possible to control Excel using POI in the way that you can with OLE.

Even though the only way to proceed with POI is to create and save a file,
what you could do is to hold the file in memory, add data to it and then
save it once the procedures have completed.

Typically, you would do something like this;

HSSFWorkbook workbook = new HSSFWorkbook();
// Procedure 1
HSSFSheet = workbook.createSheet();
// Process the data adding rows and to the sheet and cells to
// the rows as necessary
HSSFRow row = sheet.createRow(int);
HSSFCell cell = row.createCell(int);
// Procedure 2
HSSFSheet = workbook.createSheet();
// Process the data adding rows and to the sheet and cells to
// the rows as necessary
HSSFRow row = sheet.createRow(int);
HSSFCell cell = row.createCell(int);
// Procedure 3
HSSFSheet = workbook.createSheet();
// Process the data adding rows and to the sheet and cells to
// the orws as necessary
HSSFRow row = sheet.createRow(int);
HSSFCell cell = row.createCell(int);
.............................
workbook.write(new java.io.FileOutputStream(new
java.io.File("..............")));

The only caveat is that POI is quite memory intensive and there have been
problems building large workbooks. If you are targeting Office 2007 only and
looking to create OpenXML files then Yegor proposed a better solution that I
will have to see if I can find again as he outlined it all some time ago
now.

Hope thats clear. If not, I will try to put together some code to make it a
little easier to grasp, just let me know if I can be of help.


Jani Gracnar wrote:
> 
> I will explain our recent usage of calling excel from Oracle Forms with
> OLE (we are looking for different solution - maybe POI)
> 
> On button pressed we trigger next procedure:
> 1. Create Excel.Application OLE object
> 2. Data transfer (Oracle Forms to Excel)
> 3. Dispose OLE object
> We do not want to save file ofter procedure is finished!
> 
> We will like that after run our procedure one more time Excel is not
> started in one more process. Is it possible to create object with existing
> Excel application running and transfer data in new sheet (not new file).
> 
> Is the temporary file saving between two runs of procedure only solution
> of our case? For user it will be better to save Excel file after many runs
> of procedure.
> 
> Thanx for all help,
> 
> Jani
> 
> 
> 
> 
> MSB wrote:
>> 
>> Hello Jani,
>> 
>> Can I ask a question please about how you are attempting to use POI?
>> 
>> Are you expecting to have Excel open, to then use POI to create a file
>> and then, through Excel, to prompt the user to enter a name for the file?
>> If so, then this cannot be accomplished. There is no way to integrate POI
>> with Excel; POI is a tool that can be used to create files that Excel can
>> read and to open/modify files that were created using Excel.
>> 
>> Perhaps if you can explain in more detail what you are attempting to
>> accomplish then we can help you further.
>> 
>> 
>> Jani Gracnar wrote:
>>> 
>>> Thank you for your help.
>>> If I look at Quick Guide, there is a way to create new workbook:
>>> Workbook wb = new HSSFWorkbook();
>>> FileOutputStream fileOut = new FileOutputStream("workbook.xls");
>>> wb.write(fileOut);
>>> fileOut.close();
>>> 
>>> FileOutputStream need a string parameter workbook name but in my case
>>> (excel just opened manualy, no save performed) I can not specify this
>>> parameter.
>>> 
>>> Is any other way to create this object (in my situation) and then
>>> manipulate workbook?
>>> 
>>> Thanx,
>>> 
>>> Jani
>>> 
>>> 
>>> MSB wrote:
>>>> 
>>>> Yes you can do this.
>>>> 
>>>> The only restriction that I am aware of is the POI cannot work on a
>>>> file that Excel has a lock on. By this, I mean that you cannot use POI
>>>> to work on file that is already open in Excel.
>>>> 
>>>> 
>>>> 
>>>> Jani Gracnar wrote:
>>>>> 
>>>>> Hi,
>>>>> 
>>>>> Is it possible to create object of excel application which is already
>>>>> open and the file is not saved as file on disk (the state after excel
>>>>> is just started - no file name).
>>>>> 
>>>>> Thanx,
>>>>> 
>>>>> Jani
>>>>> 
>>>> 
>>>> 
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Create-object-if-Excel-is-already-open-tp23757513p23769104.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: Create object if Excel is already open

Posted by Jani Gracnar <ja...@gmail.com>.
I will explain our recent usage of calling excel from Oracle Forms with OLE
(we are looking for different solution - maybe POI)

On button pressed we trigger next procedure:
1. Create Excel.Application OLE object
2. Data transfer (Oracle Forms to Excel)
3. Dispose OLE object
We do not want to save file ofter procedure is finished!

We will like that after run our procedure one more time Excel is not started
in one more process. Is it possible to create object with existing Excel
application running and transfer data in new sheet (not new file).

Is the temporary file saving between two runs of procedure only solution of
our case? For user it will be better to save Excel file after many runs of
procedure.

Thanx for all help,

Jani




MSB wrote:
> 
> Hello Jani,
> 
> Can I ask a question please about how you are attempting to use POI?
> 
> Are you expecting to have Excel open, to then use POI to create a file and
> then, through Excel, to prompt the user to enter a name for the file? If
> so, then this cannot be accomplished. There is no way to integrate POI
> with Excel; POI is a tool that can be used to create files that Excel can
> read and to open/modify files that were created using Excel.
> 
> Perhaps if you can explain in more detail what you are attempting to
> accomplish then we can help you further.
> 
> 
> Jani Gracnar wrote:
>> 
>> Thank you for your help.
>> If I look at Quick Guide, there is a way to create new workbook:
>> Workbook wb = new HSSFWorkbook();
>> FileOutputStream fileOut = new FileOutputStream("workbook.xls");
>> wb.write(fileOut);
>> fileOut.close();
>> 
>> FileOutputStream need a string parameter workbook name but in my case
>> (excel just opened manualy, no save performed) I can not specify this
>> parameter.
>> 
>> Is any other way to create this object (in my situation) and then
>> manipulate workbook?
>> 
>> Thanx,
>> 
>> Jani
>> 
>> 
>> MSB wrote:
>>> 
>>> Yes you can do this.
>>> 
>>> The only restriction that I am aware of is the POI cannot work on a file
>>> that Excel has a lock on. By this, I mean that you cannot use POI to
>>> work on file that is already open in Excel.
>>> 
>>> 
>>> 
>>> Jani Gracnar wrote:
>>>> 
>>>> Hi,
>>>> 
>>>> Is it possible to create object of excel application which is already
>>>> open and the file is not saved as file on disk (the state after excel
>>>> is just started - no file name).
>>>> 
>>>> Thanx,
>>>> 
>>>> Jani
>>>> 
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Create-object-if-Excel-is-already-open-tp23757513p23767078.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: Create object if Excel is already open

Posted by MSB <ma...@tiscali.co.uk>.
Hello Jani,

Can I ask a question please about how you are attempting to use POI?

Are you expecting to have Excel open, to then use POI to create a file and
then, through Excel, to prompt the user to enter a name for the file? If so,
then this cannot be accomplished. There is no way to integrate POI with
Excel; POI is a tool that can be used to create files that Excel can read
and to open/modify files that were created using Excel.

Perhaps if you can explain in more detail what you are attempting to
accomplish then we can help you further.


Jani Gracnar wrote:
> 
> Thank you for your help.
> If I look at Quick Guide, there is a way to create new workbook:
> Workbook wb = new HSSFWorkbook();
> FileOutputStream fileOut = new FileOutputStream("workbook.xls");
> wb.write(fileOut);
> fileOut.close();
> 
> FileOutputStream need a string parameter workbook name but in my case
> (excel just opened manualy, no save performed) I can not specify this
> parameter.
> 
> Is any other way to create this object (in my situation) and then
> manipulate workbook?
> 
> Thanx,
> 
> Jani
> 
> 
> MSB wrote:
>> 
>> Yes you can do this.
>> 
>> The only restriction that I am aware of is the POI cannot work on a file
>> that Excel has a lock on. By this, I mean that you cannot use POI to work
>> on file that is already open in Excel.
>> 
>> 
>> 
>> Jani Gracnar wrote:
>>> 
>>> Hi,
>>> 
>>> Is it possible to create object of excel application which is already
>>> open and the file is not saved as file on disk (the state after excel is
>>> just started - no file name).
>>> 
>>> Thanx,
>>> 
>>> Jani
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Create-object-if-Excel-is-already-open-tp23757513p23762948.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: Create object if Excel is already open

Posted by Jani Gracnar <ja...@gmail.com>.
Thank you for your help.
If I look at Quick Guide, there is a way to create new workbook:
Workbook wb = new HSSFWorkbook();
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();

FileOutputStream need a string parameter workbook name but in my case (excel
just opened manualy, no save performed) I can not specify this parameter.

Is any other way to create this object (in my situation) and then manipulate
workbook?

Thanx,

Jani


MSB wrote:
> 
> Yes you can do this.
> 
> The only restriction that I am aware of is the POI cannot work on a file
> that Excel has a lock on. By this, I mean that you cannot use POI to work
> on file that is already open in Excel.
> 
> 
> 
> Jani Gracnar wrote:
>> 
>> Hi,
>> 
>> Is it possible to create object of excel application which is already
>> open and the file is not saved as file on disk (the state after excel is
>> just started - no file name).
>> 
>> Thanx,
>> 
>> Jani
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Create-object-if-Excel-is-already-open-tp23757513p23759305.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: Create object if Excel is already open

Posted by MSB <ma...@tiscali.co.uk>.
Yes you can do this.

The only restriction that I am aware of is the POI cannot work on a file
that Excel has a lock on. By this, I mean that you cannot use POI to work on
file that is already open in Excel.



Jani Gracnar wrote:
> 
> Hi,
> 
> Is it possible to create object of excel application which is already open
> and the file is not saved as file on disk (the state after excel is just
> started - no file name).
> 
> Thanx,
> 
> Jani
> 

-- 
View this message in context: http://www.nabble.com/Create-object-if-Excel-is-already-open-tp23757513p23758124.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