You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Immad Naseer <im...@gmail.com> on 2010/06/22 03:33:03 UTC

Adding paragraphs to XWPFTableCell

Hi all,

How would I add a paragraph to a XWPFTableCell? While XWPFTableCell contains
an addParagraph method, that method expects an already instantiated
paragraph object to be passed to it and there doesn't seem to be a simple
way to create stand-alone XWPFParagraph objects that I can attach to the
body or table after creation.

Is there some simple way to add paragraphs to XWPFTableCell like you can add
paragraphs to a document using XWPFDocument.createParagraph?

Regards,
Immad

PS: I am using the 3.7 beta release of POI.

Re: Adding paragraphs to XWPFTableCell

Posted by MSB <ma...@tiscali.co.uk>.
Thanks for this, I saw the patch just a few seconds ago and reckon that quite
a few people will be happy when this one is added to the api. It is
impossible to say when, but one of the development team will review the
patch and add it to the api; it may take a few days but someone will pick it
up I am sure. They may suggest changes to keep the code in line with the
projects standards but above all, I am confident they will be happy that
someone else has joined the project.

Thanks again for the contribution.

Yours

Mark B




Immad Naseer wrote:
> 
> I should have been more proactive -- thanks for the gentle nudge.
> 
> Patch submitted.
> 
> On Wed, Jun 23, 2010 at 11:53 PM, MSB <ma...@tiscali.co.uk> wrote:
> 
>>
>> Thanks for that. This is most liekely the sort of question that will
>> arise
>> again in the future. By the way (and this a very unsubtle hint for which
>> I
>> apologise), POI is a public, collaborative project and, if you wanted to
>> do
>> so (another hint), you could always download the source, modify it to
>> include an addParagraph() or newParagraph() method and then submit this
>> as
>> a
>> patch.
>>
>> Yours
>>
>> Mark B
>>
>>
>> Immad Naseer wrote:
>> >
>> > A quick follow up. It would probably be better to write:
>> >
>> > cell.addParagraph(new XWPFParagraph(cell.getCTTc().addNewP(), cell));
>> >
>> > This way the newly created paragraph gets reflected in the cell's
>> > paragraph
>> > array.
>> >
>> > Immad
>> >
>> > On Wed, Jun 23, 2010 at 10:37 AM, Immad Naseer
>> > <im...@gmail.com>wrote:
>> >
>> >> Thanks Mark -- that helped a lot.
>> >>
>> >> I tried adding the new paragraph to a XWPFTableCell using its
>> >> addParagraph
>> >> method but that didn't work; it just appended the paragraph to its
>> >> paragraph
>> >> array but didn't add anything to the underlying CTTc object..
>> >>
>> >> I looked at the source code some more and here is how I was able to do
>> >> it:
>> >>
>> >> XWPFParagraph newPara = new XWPFParagraph(cell.getCTTc().addNewP(),
>> >> cell);
>> >>
>> >> newPara.createRun().setText("Some text");
>> >>
>> >>
>> >> It sure will be nice to have a createParagraph() method on a
>> >> XWPFTableCell
>> >> in a future release of POI.
>> >>
>> >> Regards,
>> >> Immad
>> >>
>> >> On Wed, Jun 23, 2010 at 7:14 AM, MSB <ma...@tiscali.co.uk> wrote:
>> >>
>> >>>
>> >>> Try this
>> >>>
>> >>> XWPFParagraph para = new XWPFParagraph(
>> >>>
>> >>>
>> >>>
>> org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP.Factory.newInstance());
>> >>>
>> >>> That compiles and seems to run perfectly well. Of course, you will
>> then
>> >>> need
>> >>> to add runs to the paragraph in order to add any text to it but this
>> >>> shoulod
>> >>> get you started.
>> >>>
>> >>> Yours
>> >>>
>> >>> Mark B
>> >>>
>> >>>
>> >>> Immad Naseer wrote:
>> >>> >
>> >>> > Hi all,
>> >>> >
>> >>> > How would I add a paragraph to a XWPFTableCell? While XWPFTableCell
>> >>> > contains
>> >>> > an addParagraph method, that method expects an already instantiated
>> >>> > paragraph object to be passed to it and there doesn't seem to be a
>> >>> simple
>> >>> > way to create stand-alone XWPFParagraph objects that I can attach
>> to
>> >>> the
>> >>> > body or table after creation.
>> >>> >
>> >>> > Is there some simple way to add paragraphs to XWPFTableCell like
>> you
>> >>> can
>> >>> > add
>> >>> > paragraphs to a document using XWPFDocument.createParagraph?
>> >>> >
>> >>> > Regards,
>> >>> > Immad
>> >>> >
>> >>> > PS: I am using the 3.7 beta release of POI.
>> >>> >
>> >>> >
>> >>>
>> >>> --
>> >>> View this message in context:
>> >>>
>> http://old.nabble.com/Adding-paragraphs-to-XWPFTableCell-tp28955249p28972405.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://old.nabble.com/Adding-paragraphs-to-XWPFTableCell-tp28955249p28979453.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://old.nabble.com/Adding-paragraphs-to-XWPFTableCell-tp28955249p29004176.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: Adding paragraphs to XWPFTableCell

Posted by Immad Naseer <im...@gmail.com>.
I should have been more proactive -- thanks for the gentle nudge.

Patch submitted.

On Wed, Jun 23, 2010 at 11:53 PM, MSB <ma...@tiscali.co.uk> wrote:

>
> Thanks for that. This is most liekely the sort of question that will arise
> again in the future. By the way (and this a very unsubtle hint for which I
> apologise), POI is a public, collaborative project and, if you wanted to do
> so (another hint), you could always download the source, modify it to
> include an addParagraph() or newParagraph() method and then submit this as
> a
> patch.
>
> Yours
>
> Mark B
>
>
> Immad Naseer wrote:
> >
> > A quick follow up. It would probably be better to write:
> >
> > cell.addParagraph(new XWPFParagraph(cell.getCTTc().addNewP(), cell));
> >
> > This way the newly created paragraph gets reflected in the cell's
> > paragraph
> > array.
> >
> > Immad
> >
> > On Wed, Jun 23, 2010 at 10:37 AM, Immad Naseer
> > <im...@gmail.com>wrote:
> >
> >> Thanks Mark -- that helped a lot.
> >>
> >> I tried adding the new paragraph to a XWPFTableCell using its
> >> addParagraph
> >> method but that didn't work; it just appended the paragraph to its
> >> paragraph
> >> array but didn't add anything to the underlying CTTc object..
> >>
> >> I looked at the source code some more and here is how I was able to do
> >> it:
> >>
> >> XWPFParagraph newPara = new XWPFParagraph(cell.getCTTc().addNewP(),
> >> cell);
> >>
> >> newPara.createRun().setText("Some text");
> >>
> >>
> >> It sure will be nice to have a createParagraph() method on a
> >> XWPFTableCell
> >> in a future release of POI.
> >>
> >> Regards,
> >> Immad
> >>
> >> On Wed, Jun 23, 2010 at 7:14 AM, MSB <ma...@tiscali.co.uk> wrote:
> >>
> >>>
> >>> Try this
> >>>
> >>> XWPFParagraph para = new XWPFParagraph(
> >>>
> >>>
> >>>
> org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP.Factory.newInstance());
> >>>
> >>> That compiles and seems to run perfectly well. Of course, you will then
> >>> need
> >>> to add runs to the paragraph in order to add any text to it but this
> >>> shoulod
> >>> get you started.
> >>>
> >>> Yours
> >>>
> >>> Mark B
> >>>
> >>>
> >>> Immad Naseer wrote:
> >>> >
> >>> > Hi all,
> >>> >
> >>> > How would I add a paragraph to a XWPFTableCell? While XWPFTableCell
> >>> > contains
> >>> > an addParagraph method, that method expects an already instantiated
> >>> > paragraph object to be passed to it and there doesn't seem to be a
> >>> simple
> >>> > way to create stand-alone XWPFParagraph objects that I can attach to
> >>> the
> >>> > body or table after creation.
> >>> >
> >>> > Is there some simple way to add paragraphs to XWPFTableCell like you
> >>> can
> >>> > add
> >>> > paragraphs to a document using XWPFDocument.createParagraph?
> >>> >
> >>> > Regards,
> >>> > Immad
> >>> >
> >>> > PS: I am using the 3.7 beta release of POI.
> >>> >
> >>> >
> >>>
> >>> --
> >>> View this message in context:
> >>>
> http://old.nabble.com/Adding-paragraphs-to-XWPFTableCell-tp28955249p28972405.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://old.nabble.com/Adding-paragraphs-to-XWPFTableCell-tp28955249p28979453.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: Adding paragraphs to XWPFTableCell

Posted by MSB <ma...@tiscali.co.uk>.
Thanks for that. This is most liekely the sort of question that will arise
again in the future. By the way (and this a very unsubtle hint for which I
apologise), POI is a public, collaborative project and, if you wanted to do
so (another hint), you could always download the source, modify it to
include an addParagraph() or newParagraph() method and then submit this as a
patch.

Yours

Mark B


Immad Naseer wrote:
> 
> A quick follow up. It would probably be better to write:
> 
> cell.addParagraph(new XWPFParagraph(cell.getCTTc().addNewP(), cell));
> 
> This way the newly created paragraph gets reflected in the cell's
> paragraph
> array.
> 
> Immad
> 
> On Wed, Jun 23, 2010 at 10:37 AM, Immad Naseer
> <im...@gmail.com>wrote:
> 
>> Thanks Mark -- that helped a lot.
>>
>> I tried adding the new paragraph to a XWPFTableCell using its
>> addParagraph
>> method but that didn't work; it just appended the paragraph to its
>> paragraph
>> array but didn't add anything to the underlying CTTc object..
>>
>> I looked at the source code some more and here is how I was able to do
>> it:
>>
>> XWPFParagraph newPara = new XWPFParagraph(cell.getCTTc().addNewP(),
>> cell);
>>
>> newPara.createRun().setText("Some text");
>>
>>
>> It sure will be nice to have a createParagraph() method on a
>> XWPFTableCell
>> in a future release of POI.
>>
>> Regards,
>> Immad
>>
>> On Wed, Jun 23, 2010 at 7:14 AM, MSB <ma...@tiscali.co.uk> wrote:
>>
>>>
>>> Try this
>>>
>>> XWPFParagraph para = new XWPFParagraph(
>>>
>>>
>>> org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP.Factory.newInstance());
>>>
>>> That compiles and seems to run perfectly well. Of course, you will then
>>> need
>>> to add runs to the paragraph in order to add any text to it but this
>>> shoulod
>>> get you started.
>>>
>>> Yours
>>>
>>> Mark B
>>>
>>>
>>> Immad Naseer wrote:
>>> >
>>> > Hi all,
>>> >
>>> > How would I add a paragraph to a XWPFTableCell? While XWPFTableCell
>>> > contains
>>> > an addParagraph method, that method expects an already instantiated
>>> > paragraph object to be passed to it and there doesn't seem to be a
>>> simple
>>> > way to create stand-alone XWPFParagraph objects that I can attach to
>>> the
>>> > body or table after creation.
>>> >
>>> > Is there some simple way to add paragraphs to XWPFTableCell like you
>>> can
>>> > add
>>> > paragraphs to a document using XWPFDocument.createParagraph?
>>> >
>>> > Regards,
>>> > Immad
>>> >
>>> > PS: I am using the 3.7 beta release of POI.
>>> >
>>> >
>>>
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Adding-paragraphs-to-XWPFTableCell-tp28955249p28972405.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://old.nabble.com/Adding-paragraphs-to-XWPFTableCell-tp28955249p28979453.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: Adding paragraphs to XWPFTableCell

Posted by Immad Naseer <im...@gmail.com>.
A quick follow up. It would probably be better to write:

cell.addParagraph(new XWPFParagraph(cell.getCTTc().addNewP(), cell));

This way the newly created paragraph gets reflected in the cell's paragraph
array.

Immad

On Wed, Jun 23, 2010 at 10:37 AM, Immad Naseer <im...@gmail.com>wrote:

> Thanks Mark -- that helped a lot.
>
> I tried adding the new paragraph to a XWPFTableCell using its addParagraph
> method but that didn't work; it just appended the paragraph to its paragraph
> array but didn't add anything to the underlying CTTc object..
>
> I looked at the source code some more and here is how I was able to do it:
>
> XWPFParagraph newPara = new XWPFParagraph(cell.getCTTc().addNewP(), cell);
>
> newPara.createRun().setText("Some text");
>
>
> It sure will be nice to have a createParagraph() method on a XWPFTableCell
> in a future release of POI.
>
> Regards,
> Immad
>
> On Wed, Jun 23, 2010 at 7:14 AM, MSB <ma...@tiscali.co.uk> wrote:
>
>>
>> Try this
>>
>> XWPFParagraph para = new XWPFParagraph(
>>
>>
>> org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP.Factory.newInstance());
>>
>> That compiles and seems to run perfectly well. Of course, you will then
>> need
>> to add runs to the paragraph in order to add any text to it but this
>> shoulod
>> get you started.
>>
>> Yours
>>
>> Mark B
>>
>>
>> Immad Naseer wrote:
>> >
>> > Hi all,
>> >
>> > How would I add a paragraph to a XWPFTableCell? While XWPFTableCell
>> > contains
>> > an addParagraph method, that method expects an already instantiated
>> > paragraph object to be passed to it and there doesn't seem to be a
>> simple
>> > way to create stand-alone XWPFParagraph objects that I can attach to the
>> > body or table after creation.
>> >
>> > Is there some simple way to add paragraphs to XWPFTableCell like you can
>> > add
>> > paragraphs to a document using XWPFDocument.createParagraph?
>> >
>> > Regards,
>> > Immad
>> >
>> > PS: I am using the 3.7 beta release of POI.
>> >
>> >
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Adding-paragraphs-to-XWPFTableCell-tp28955249p28972405.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: Adding paragraphs to XWPFTableCell

Posted by Immad Naseer <im...@gmail.com>.
Thanks Mark -- that helped a lot.

I tried adding the new paragraph to a XWPFTableCell using its addParagraph
method but that didn't work; it just appended the paragraph to its paragraph
array but didn't add anything to the underlying CTTc object..

I looked at the source code some more and here is how I was able to do it:

XWPFParagraph newPara = new XWPFParagraph(cell.getCTTc().addNewP(), cell);

newPara.createRun().setText("Some text");


It sure will be nice to have a createParagraph() method on a XWPFTableCell
in a future release of POI.

Regards,
Immad

On Wed, Jun 23, 2010 at 7:14 AM, MSB <ma...@tiscali.co.uk> wrote:

>
> Try this
>
> XWPFParagraph para = new XWPFParagraph(
>
>
> org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP.Factory.newInstance());
>
> That compiles and seems to run perfectly well. Of course, you will then
> need
> to add runs to the paragraph in order to add any text to it but this
> shoulod
> get you started.
>
> Yours
>
> Mark B
>
>
> Immad Naseer wrote:
> >
> > Hi all,
> >
> > How would I add a paragraph to a XWPFTableCell? While XWPFTableCell
> > contains
> > an addParagraph method, that method expects an already instantiated
> > paragraph object to be passed to it and there doesn't seem to be a simple
> > way to create stand-alone XWPFParagraph objects that I can attach to the
> > body or table after creation.
> >
> > Is there some simple way to add paragraphs to XWPFTableCell like you can
> > add
> > paragraphs to a document using XWPFDocument.createParagraph?
> >
> > Regards,
> > Immad
> >
> > PS: I am using the 3.7 beta release of POI.
> >
> >
>
> --
> View this message in context:
> http://old.nabble.com/Adding-paragraphs-to-XWPFTableCell-tp28955249p28972405.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: Adding paragraphs to XWPFTableCell

Posted by MSB <ma...@tiscali.co.uk>.
Try this

XWPFParagraph para = new XWPFParagraph(
   
org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP.Factory.newInstance());

That compiles and seems to run perfectly well. Of course, you will then need
to add runs to the paragraph in order to add any text to it but this shoulod
get you started.

Yours

Mark B


Immad Naseer wrote:
> 
> Hi all,
> 
> How would I add a paragraph to a XWPFTableCell? While XWPFTableCell
> contains
> an addParagraph method, that method expects an already instantiated
> paragraph object to be passed to it and there doesn't seem to be a simple
> way to create stand-alone XWPFParagraph objects that I can attach to the
> body or table after creation.
> 
> Is there some simple way to add paragraphs to XWPFTableCell like you can
> add
> paragraphs to a document using XWPFDocument.createParagraph?
> 
> Regards,
> Immad
> 
> PS: I am using the 3.7 beta release of POI.
> 
> 

-- 
View this message in context: http://old.nabble.com/Adding-paragraphs-to-XWPFTableCell-tp28955249p28972405.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: Adding paragraphs to XWPFTableCell

Posted by MSB <ma...@tiscali.co.uk>.
Late last night,m it ocurred to me that I think I know how to do this - in
fact I think that I already have using the Factory method of the CTP class
to create an instance that is then used to initialise an XWPFParagraph
object - but I need to test some code out before posting again.

Will post again once I have had the chance to lay around a bit.

Yours

Mark B


Immad Naseer wrote:
> 
> Hi all,
> 
> How would I add a paragraph to a XWPFTableCell? While XWPFTableCell
> contains
> an addParagraph method, that method expects an already instantiated
> paragraph object to be passed to it and there doesn't seem to be a simple
> way to create stand-alone XWPFParagraph objects that I can attach to the
> body or table after creation.
> 
> Is there some simple way to add paragraphs to XWPFTableCell like you can
> add
> paragraphs to a document using XWPFDocument.createParagraph?
> 
> Regards,
> Immad
> 
> PS: I am using the 3.7 beta release of POI.
> 
> 

-- 
View this message in context: http://old.nabble.com/Adding-paragraphs-to-XWPFTableCell-tp28955249p28968760.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