You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by gliao <gl...@gmail.com> on 2008/09/03 19:12:06 UTC
Re: merge worksheets from mutiple xls files
Hi Nick,
Thanks a lot. Is there any sample code about this?
George
Nick Burch wrote:
>
> On Fri, 29 Aug 2008, gliao wrote:
>> Does the style including font and color? If it does, why it doen't copy
>> font and color, even the code already set copyStyle boolean as true? Any
>> idea.
>
> Styles are specific to just one workbook. I think you'll be wanting this:
>
> http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFCellStyle.html#cloneStyleFrom(org.apache.poi.hssf.usermodel.HSSFCellStyle)
>
> "Clones all the style information from another HSSFCellStyle, onto this
> one. This HSSFCellStyle will then have all the same properties as the
> source, but the two may be edited independently. Any stylings on this
> HSSFCellStyle will be lost! The source HSSFCellStyle could be from another
> HSSFWorkbook if you like. This allows you to copy styles from one
> HSSFWorkbook to another."
>
> Nick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/merge-worksheets-from-mutiple-xls-files-tp19168828p19293663.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: merge worksheets from mutiple xls files
Posted by Anthony Andrews <py...@yahoo.com>.
No problem, enjoy problems like this one. Will have a look later today and post something out (hopefully) this evening.
--- On Thu, 9/4/08, gliao <gl...@gmail.com> wrote:
From: gliao <gl...@gmail.com>
Subject: Re: merge worksheets from mutiple xls files
To: user@poi.apache.org
Date: Thursday, September 4, 2008, 12:20 AM
I am still using the copy sheet code you provided. I appreciate your help.
Anthony Andrews wrote:
>
> Are you still using that same basic piece of code to copy the sheets
> between workbooks? If so I will take a look today and see how to modify
> that to use the cloneStyle() method.
>
> --- On Wed, 9/3/08, gliao <gl...@gmail.com> wrote:
> From: gliao <gl...@gmail.com>
> Subject: Re: merge worksheets from mutiple xls files
> To: user@poi.apache.org
> Date: Wednesday, September 3, 2008, 10:12 AM
>
> Hi Nick,
>
> Thanks a lot. Is there any sample code about this?
>
> George
>
> Nick Burch wrote:
>>
>> On Fri, 29 Aug 2008, gliao wrote:
>>> Does the style including font and color? If it does, why it
doen't
> copy
>>> font and color, even the code already set copyStyle boolean as
true?
> Any
>>> idea.
>>
>> Styles are specific to just one workbook. I think you'll be
wanting
> this:
>>
>>
>
http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFCellStyle.html#cloneStyleFrom(org.apache.poi.hssf.usermodel.HSSFCellStyle)
>>
>> "Clones all the style information from another HSSFCellStyle,
onto
> this
>> one. This HSSFCellStyle will then have all the same properties as the
>> source, but the two may be edited independently. Any stylings on this
>> HSSFCellStyle will be lost! The source HSSFCellStyle could be from
>> another
>
>> HSSFWorkbook if you like. This allows you to copy styles from one
>> HSSFWorkbook to another."
>>
>> Nick
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>> For additional commands, e-mail: user-help@poi.apache.org
>>
>>
>>
>
> --
> View this message in context:
>
http://www.nabble.com/merge-worksheets-from-mutiple-xls-files-tp19168828p19293663.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
>
>
>
>
>
>
--
View this message in context:
http://www.nabble.com/merge-worksheets-from-mutiple-xls-files-tp19168828p19304763.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: merge worksheets from mutiple xls files
Posted by gliao <gl...@gmail.com>.
I am still using the copy sheet code you provided. I appreciate your help.
Anthony Andrews wrote:
>
> Are you still using that same basic piece of code to copy the sheets
> between workbooks? If so I will take a look today and see how to modify
> that to use the cloneStyle() method.
>
> --- On Wed, 9/3/08, gliao <gl...@gmail.com> wrote:
> From: gliao <gl...@gmail.com>
> Subject: Re: merge worksheets from mutiple xls files
> To: user@poi.apache.org
> Date: Wednesday, September 3, 2008, 10:12 AM
>
> Hi Nick,
>
> Thanks a lot. Is there any sample code about this?
>
> George
>
> Nick Burch wrote:
>>
>> On Fri, 29 Aug 2008, gliao wrote:
>>> Does the style including font and color? If it does, why it doen't
> copy
>>> font and color, even the code already set copyStyle boolean as true?
> Any
>>> idea.
>>
>> Styles are specific to just one workbook. I think you'll be wanting
> this:
>>
>>
> http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFCellStyle.html#cloneStyleFrom(org.apache.poi.hssf.usermodel.HSSFCellStyle)
>>
>> "Clones all the style information from another HSSFCellStyle, onto
> this
>> one. This HSSFCellStyle will then have all the same properties as the
>> source, but the two may be edited independently. Any stylings on this
>> HSSFCellStyle will be lost! The source HSSFCellStyle could be from
>> another
>
>> HSSFWorkbook if you like. This allows you to copy styles from one
>> HSSFWorkbook to another."
>>
>> Nick
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>> For additional commands, e-mail: user-help@poi.apache.org
>>
>>
>>
>
> --
> View this message in context:
> http://www.nabble.com/merge-worksheets-from-mutiple-xls-files-tp19168828p19293663.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
>
>
>
>
>
>
--
View this message in context: http://www.nabble.com/merge-worksheets-from-mutiple-xls-files-tp19168828p19304763.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: merge worksheets from mutiple xls files
Posted by Anthony Andrews <py...@yahoo.com>.
Are you still using that same basic piece of code to copy the sheets between workbooks? If so I will take a look today and see how to modify that to use the cloneStyle() method.
--- On Wed, 9/3/08, gliao <gl...@gmail.com> wrote:
From: gliao <gl...@gmail.com>
Subject: Re: merge worksheets from mutiple xls files
To: user@poi.apache.org
Date: Wednesday, September 3, 2008, 10:12 AM
Hi Nick,
Thanks a lot. Is there any sample code about this?
George
Nick Burch wrote:
>
> On Fri, 29 Aug 2008, gliao wrote:
>> Does the style including font and color? If it does, why it doen't
copy
>> font and color, even the code already set copyStyle boolean as true?
Any
>> idea.
>
> Styles are specific to just one workbook. I think you'll be wanting
this:
>
>
http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFCellStyle.html#cloneStyleFrom(org.apache.poi.hssf.usermodel.HSSFCellStyle)
>
> "Clones all the style information from another HSSFCellStyle, onto
this
> one. This HSSFCellStyle will then have all the same properties as the
> source, but the two may be edited independently. Any stylings on this
> HSSFCellStyle will be lost! The source HSSFCellStyle could be from another
> HSSFWorkbook if you like. This allows you to copy styles from one
> HSSFWorkbook to another."
>
> Nick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>
>
--
View this message in context:
http://www.nabble.com/merge-worksheets-from-mutiple-xls-files-tp19168828p19293663.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: merge worksheets from mutiple xls files - where is clone method
please?
Posted by "Kyle.Bober" <ky...@gmail.com>.
Has there been any updates or an easier more clean solution for copying a
worksheet from one workbook to another?
Any new information regarding how to do this appropriately would be much
appreciated.
-Kyle
Anthony Andrews wrote:
>
> Thanks Nick. I managed to find it in an archive from the nightly build
> section as you recommended to another poster (sorry to ask a question that
> someone already had by the way). Also, glad to say that it seems to work -
> at least in the quick and dirty bit of test code I put together.
>
> --- On Thu, 9/4/08, Nick Burch <ni...@torchbox.com> wrote:
> From: Nick Burch <ni...@torchbox.com>
> Subject: Re: merge worksheets from mutiple xls files - where is clone
> method please?
> To: "POI Users List" <us...@poi.apache.org>, pythonaddict@yahoo.com
> Date: Thursday, September 4, 2008, 9:53 AM
>
> On Thu, 4 Sep 2008, Anthony Andrews wrote:
>> Can you tell me please which version the HSSFCellStyle.cloneStyleFrom()
>> method can be found within? I have downloaded 3.5 beta1 from the
>> development section and cannot find the method there.
>
> You'll want a recent-ish svn checkout, or the next beta from 3.1 or 3.5
> when they come out
>
> Nick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>
>
>
>
>
--
View this message in context: http://www.nabble.com/merge-worksheets-from-mutiple-xls-files-tp19168828p24592225.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: merge worksheets from mutiple xls files - where is clone method please?
Posted by Anthony Andrews <py...@yahoo.com>.
Thanks Nick. I managed to find it in an archive from the nightly build section as you recommended to another poster (sorry to ask a question that someone already had by the way). Also, glad to say that it seems to work - at least in the quick and dirty bit of test code I put together.
--- On Thu, 9/4/08, Nick Burch <ni...@torchbox.com> wrote:
From: Nick Burch <ni...@torchbox.com>
Subject: Re: merge worksheets from mutiple xls files - where is clone method please?
To: "POI Users List" <us...@poi.apache.org>, pythonaddict@yahoo.com
Date: Thursday, September 4, 2008, 9:53 AM
On Thu, 4 Sep 2008, Anthony Andrews wrote:
> Can you tell me please which version the HSSFCellStyle.cloneStyleFrom()
> method can be found within? I have downloaded 3.5 beta1 from the
> development section and cannot find the method there.
You'll want a recent-ish svn checkout, or the next beta from 3.1 or 3.5
when they come out
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: merge worksheets from mutiple xls files - where is clone method
please?
Posted by Nick Burch <ni...@torchbox.com>.
On Thu, 4 Sep 2008, Anthony Andrews wrote:
> Can you tell me please which version the HSSFCellStyle.cloneStyleFrom()
> method can be found within? I have downloaded 3.5 beta1 from the
> development section and cannot find the method there.
You'll want a recent-ish svn checkout, or the next beta from 3.1 or 3.5
when they come out
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: merge worksheets from mutiple xls files - where is clone method please?
Posted by Anthony Andrews <py...@yahoo.com>.
Nick
Can you tell me please which version the HSSFCellStyle.cloneStyleFrom() method can be found within? I have downloaded 3.5 beta1 from the development section and cannot find the method there.
--- On Thu, 9/4/08, Nick Burch <ni...@torchbox.com> wrote:
From: Nick Burch <ni...@torchbox.com>
Subject: Re: merge worksheets from mutiple xls files
To: "POI Users List" <us...@poi.apache.org>
Date: Thursday, September 4, 2008, 2:29 AM
On Wed, 3 Sep 2008, gliao wrote:
> Thanks a lot. Is there any sample code about this?
Check the unit tests. It's a fairly new feature, so it's covered by the
unit tests, but possibly not by stand-alone examples
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: merge worksheets from mutiple xls files
Posted by Anthony Andrews <py...@yahoo.com>.
Sorry to say that I have not had a lot of success because I could not locate the cloneStyleFrom() method that Nick referred to (I have posted a message here asking him to point me in the direction of the archive that holds it).
I suspect that once we have found this method, then there are a couple of simple changes that must be made to the copy code. The first is in the copyCell() method where I suspect this line;
if( copyStyle ){
newCell.setCellStyle(oldCell.getCellStyle());
}
can simply be replaced with call to the cloneStyleFrom() method.
The other hurdle to overcome will be preventing our code from creating duplicate HSSFCellStyle objects. By this, I mean that it is common for cells that have the same format to share a single HSSFCellStyle object. We cannot create multiple objects if the cells share identical formatting but I suspect this should be relativly easy to avoid using some sort of mapping.
--- On Thu, 9/4/08, gliao <gl...@gmail.com> wrote:
From: gliao <gl...@gmail.com>
Subject: Re: merge worksheets from mutiple xls files
To: user@poi.apache.org
Date: Thursday, September 4, 2008, 6:03 AM
Thanks for your reply, Nick. Could you tell me the URL of the unit test code?
Nick Burch wrote:
>
> On Wed, 3 Sep 2008, gliao wrote:
>> Thanks a lot. Is there any sample code about this?
>
> Check the unit tests. It's a fairly new feature, so it's covered
by the
> unit tests, but possibly not by stand-alone examples
>
> Nick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>
>
--
View this message in context:
http://www.nabble.com/merge-worksheets-from-mutiple-xls-files-tp19168828p19308996.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: merge worksheets from mutiple xls files
Posted by Nick Burch <ni...@torchbox.com>.
On Thu, 4 Sep 2008, gliao wrote:
> Thanks for your reply, Nick. Could you tell me the URL of the unit test
> code?
http://svn.apache.org/repos/asf/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: merge worksheets from mutiple xls files
Posted by gliao <gl...@gmail.com>.
Thanks for your reply, Nick. Could you tell me the URL of the unit test code?
Nick Burch wrote:
>
> On Wed, 3 Sep 2008, gliao wrote:
>> Thanks a lot. Is there any sample code about this?
>
> Check the unit tests. It's a fairly new feature, so it's covered by the
> unit tests, but possibly not by stand-alone examples
>
> Nick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/merge-worksheets-from-mutiple-xls-files-tp19168828p19308996.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: merge worksheets from mutiple xls files
Posted by Nick Burch <ni...@torchbox.com>.
On Wed, 3 Sep 2008, gliao wrote:
> Thanks a lot. Is there any sample code about this?
Check the unit tests. It's a fairly new feature, so it's covered by the
unit tests, but possibly not by stand-alone examples
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org