You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Thorsten Bux <Th...@hype.de> on 2008/08/20 12:37:33 UTC
How to know if a shape is a table
Hi,
I'm trying to read all shape from a PPT-File and cast them into there
specific type.
Can anyone tell my how to find out if there is a table in a shape or if a
shape is a table.
Thanks a lot
Thorsten
Re: How to know if a shape is a table
Posted by Yegor Kozlov <ye...@dinom.ru>.
No, there is not other way.
For now, the Table object is used ONLY to create new tables. Modifying existing ones is not yet supported.
Even if you cast ShapeGroup to Table it won't give you much.
Yegor
> Thanks again,
>
> is there any other way to get the table-object?
>
> I need it to access the table specific methods.
>
> Thanks
> Thorsten
>
> -------- Original-Nachricht --------
>> Datum: Wed, 20 Aug 2008 16:28:54 +0400
>> Von: Yegor Kozlov <ye...@dinom.ru>
>> An: POI Users List <us...@poi.apache.org>
>> Betreff: Re: How to know if a shape is a table
>
>> You can't cast because Slide.getShapes() returns the ShapeGroup objects,
>> not Table.
>>
>> Yegor
>>
>>> thanks for your quick answer.
>>>
>>> i allready tryed
>>> if(slide instanceof table)
>>> it is not working
>>>
>>> your hack is working, but i can not cast the ShapeGroup to a Table
>>>
>>> if(isTable(shape))
>>> Table t = (Table) shape;
>>>
>>> that throws a ClassCastException
>>>
>>> Do you have any ideas how to cast a shape into a table?
>>>
>>> Thanks
>>> Thorsten
>>>
>>> -------- Original-Nachricht --------
>>>> Datum: Wed, 20 Aug 2008 15:08:40 +0400
>>>> Von: Yegor Kozlov <ye...@dinom.ru>
>>>> An: POI Users List <us...@poi.apache.org>
>>>> Betreff: Re: How to know if a shape is a table
>>>> The code looks a bit hacky but works in my tests:
>>>>
>>>> /**
>>>> * Check whether this group of shapes is a PPT table
>>>> */
>>>> public static boolean isTable(ShapeGroup shape){
>>>> EscherContainerRecord spContainer = shape.getSpContainer();
>>>>
>>>> //PPT table has a special property set with recordId=0xF122
>>>> UnknownEscherRecord opt =
>>>>
>> (UnknownEscherRecord)Shape.getEscherChild((EscherContainerRecord)spContainer.getChild(0),
>>>> (short)0xF122);
>>>> if(opt != null) {
>>>> EscherPropertyFactory f = new EscherPropertyFactory();
>>>> List props = f.createProperties( opt.getData(), 0,
>>>> opt.getInstance() );
>>>> EscherSimpleProperty p =
>> (EscherSimpleProperty)props.get(0);
>>>> //not sure if this heuristic "works" in 100% of cases
>>>> if(p.getPropertyNumber() == 0x39F && p.getPropertyValue()
>> ==
>>>> 1){
>>>> return true;
>>>> }
>>>> }
>>>> return false;
>>>> }
>>>>
>>>> Actually, Slide.getShapes() should return correct instances of shapes
>> and
>>>> the "instanceof Table" approach should work.
>>>> This isn't yet finished, so use the hack above.
>>>>
>>>> Yegor
>>>>> Hi,
>>>>>
>>>>>
>>>>>
>>>>> I'm trying to read all shape from a PPT-File and cast them into there
>>>>> specific type.
>>>>>
>>>>>
>>>>>
>>>>> Can anyone tell my how to find out if there is a table in a shape or
>> if
>>>> a
>>>>> shape is a table.
>>>>>
>>>>>
>>>>>
>>>>> Thanks a lot
>>>>>
>>>>> Thorsten
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>> ---------------------------------------------------------------------
>>>> 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: How to know if a shape is a table
Posted by Thorsten Bux <Th...@gmx.de>.
Thanks again,
is there any other way to get the table-object?
I need it to access the table specific methods.
Thanks
Thorsten
-------- Original-Nachricht --------
> Datum: Wed, 20 Aug 2008 16:28:54 +0400
> Von: Yegor Kozlov <ye...@dinom.ru>
> An: POI Users List <us...@poi.apache.org>
> Betreff: Re: How to know if a shape is a table
> You can't cast because Slide.getShapes() returns the ShapeGroup objects,
> not Table.
>
> Yegor
>
> > thanks for your quick answer.
> >
> > i allready tryed
> > if(slide instanceof table)
> > it is not working
> >
> > your hack is working, but i can not cast the ShapeGroup to a Table
> >
> > if(isTable(shape))
> > Table t = (Table) shape;
> >
> > that throws a ClassCastException
> >
> > Do you have any ideas how to cast a shape into a table?
> >
> > Thanks
> > Thorsten
> >
> > -------- Original-Nachricht --------
> >> Datum: Wed, 20 Aug 2008 15:08:40 +0400
> >> Von: Yegor Kozlov <ye...@dinom.ru>
> >> An: POI Users List <us...@poi.apache.org>
> >> Betreff: Re: How to know if a shape is a table
> >
> >> The code looks a bit hacky but works in my tests:
> >>
> >> /**
> >> * Check whether this group of shapes is a PPT table
> >> */
> >> public static boolean isTable(ShapeGroup shape){
> >> EscherContainerRecord spContainer = shape.getSpContainer();
> >>
> >> //PPT table has a special property set with recordId=0xF122
> >> UnknownEscherRecord opt =
> >>
> (UnknownEscherRecord)Shape.getEscherChild((EscherContainerRecord)spContainer.getChild(0),
> >> (short)0xF122);
> >> if(opt != null) {
> >> EscherPropertyFactory f = new EscherPropertyFactory();
> >> List props = f.createProperties( opt.getData(), 0,
> >> opt.getInstance() );
> >> EscherSimpleProperty p =
> (EscherSimpleProperty)props.get(0);
> >> //not sure if this heuristic "works" in 100% of cases
> >> if(p.getPropertyNumber() == 0x39F && p.getPropertyValue()
> ==
> >> 1){
> >> return true;
> >> }
> >> }
> >> return false;
> >> }
> >>
> >> Actually, Slide.getShapes() should return correct instances of shapes
> and
> >> the "instanceof Table" approach should work.
> >> This isn't yet finished, so use the hack above.
> >>
> >> Yegor
> >>> Hi,
> >>>
> >>>
> >>>
> >>> I'm trying to read all shape from a PPT-File and cast them into there
> >>> specific type.
> >>>
> >>>
> >>>
> >>> Can anyone tell my how to find out if there is a table in a shape or
> if
> >> a
> >>> shape is a table.
> >>>
> >>>
> >>>
> >>> Thanks a lot
> >>>
> >>> Thorsten
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>
> >> ---------------------------------------------------------------------
> >> 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
--
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: How to know if a shape is a table
Posted by Yegor Kozlov <ye...@dinom.ru>.
You can't cast because Slide.getShapes() returns the ShapeGroup objects, not Table.
Yegor
> thanks for your quick answer.
>
> i allready tryed
> if(slide instanceof table)
> it is not working
>
> your hack is working, but i can not cast the ShapeGroup to a Table
>
> if(isTable(shape))
> Table t = (Table) shape;
>
> that throws a ClassCastException
>
> Do you have any ideas how to cast a shape into a table?
>
> Thanks
> Thorsten
>
> -------- Original-Nachricht --------
>> Datum: Wed, 20 Aug 2008 15:08:40 +0400
>> Von: Yegor Kozlov <ye...@dinom.ru>
>> An: POI Users List <us...@poi.apache.org>
>> Betreff: Re: How to know if a shape is a table
>
>> The code looks a bit hacky but works in my tests:
>>
>> /**
>> * Check whether this group of shapes is a PPT table
>> */
>> public static boolean isTable(ShapeGroup shape){
>> EscherContainerRecord spContainer = shape.getSpContainer();
>>
>> //PPT table has a special property set with recordId=0xF122
>> UnknownEscherRecord opt =
>> (UnknownEscherRecord)Shape.getEscherChild((EscherContainerRecord)spContainer.getChild(0),
>> (short)0xF122);
>> if(opt != null) {
>> EscherPropertyFactory f = new EscherPropertyFactory();
>> List props = f.createProperties( opt.getData(), 0,
>> opt.getInstance() );
>> EscherSimpleProperty p = (EscherSimpleProperty)props.get(0);
>> //not sure if this heuristic "works" in 100% of cases
>> if(p.getPropertyNumber() == 0x39F && p.getPropertyValue() ==
>> 1){
>> return true;
>> }
>> }
>> return false;
>> }
>>
>> Actually, Slide.getShapes() should return correct instances of shapes and
>> the "instanceof Table" approach should work.
>> This isn't yet finished, so use the hack above.
>>
>> Yegor
>>> Hi,
>>>
>>>
>>>
>>> I'm trying to read all shape from a PPT-File and cast them into there
>>> specific type.
>>>
>>>
>>>
>>> Can anyone tell my how to find out if there is a table in a shape or if
>> a
>>> shape is a table.
>>>
>>>
>>>
>>> Thanks a lot
>>>
>>> Thorsten
>>>
>>>
>>>
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> 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: How to know if a shape is a table
Posted by Thorsten Bux <Th...@gmx.de>.
Hi,
thanks for your quick answer.
i allready tryed
if(slide instanceof table)
it is not working
your hack is working, but i can not cast the ShapeGroup to a Table
if(isTable(shape))
Table t = (Table) shape;
that throws a ClassCastException
Do you have any ideas how to cast a shape into a table?
Thanks
Thorsten
-------- Original-Nachricht --------
> Datum: Wed, 20 Aug 2008 15:08:40 +0400
> Von: Yegor Kozlov <ye...@dinom.ru>
> An: POI Users List <us...@poi.apache.org>
> Betreff: Re: How to know if a shape is a table
> The code looks a bit hacky but works in my tests:
>
> /**
> * Check whether this group of shapes is a PPT table
> */
> public static boolean isTable(ShapeGroup shape){
> EscherContainerRecord spContainer = shape.getSpContainer();
>
> //PPT table has a special property set with recordId=0xF122
> UnknownEscherRecord opt =
> (UnknownEscherRecord)Shape.getEscherChild((EscherContainerRecord)spContainer.getChild(0),
> (short)0xF122);
> if(opt != null) {
> EscherPropertyFactory f = new EscherPropertyFactory();
> List props = f.createProperties( opt.getData(), 0,
> opt.getInstance() );
> EscherSimpleProperty p = (EscherSimpleProperty)props.get(0);
> //not sure if this heuristic "works" in 100% of cases
> if(p.getPropertyNumber() == 0x39F && p.getPropertyValue() ==
> 1){
> return true;
> }
> }
> return false;
> }
>
> Actually, Slide.getShapes() should return correct instances of shapes and
> the "instanceof Table" approach should work.
> This isn't yet finished, so use the hack above.
>
> Yegor
> > Hi,
> >
> >
> >
> > I'm trying to read all shape from a PPT-File and cast them into there
> > specific type.
> >
> >
> >
> > Can anyone tell my how to find out if there is a table in a shape or if
> a
> > shape is a table.
> >
> >
> >
> > Thanks a lot
> >
> > Thorsten
> >
> >
> >
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
--
GMX Kostenlose Spiele: Einfach online spielen und Spaß haben mit Pastry Passion!
http://games.entertainment.gmx.net/de/entertainment/games/free/puzzle/6169196
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: How to know if a shape is a table
Posted by Yegor Kozlov <ye...@dinom.ru>.
The code looks a bit hacky but works in my tests:
/**
* Check whether this group of shapes is a PPT table
*/
public static boolean isTable(ShapeGroup shape){
EscherContainerRecord spContainer = shape.getSpContainer();
//PPT table has a special property set with recordId=0xF122
UnknownEscherRecord opt =
(UnknownEscherRecord)Shape.getEscherChild((EscherContainerRecord)spContainer.getChild(0), (short)0xF122);
if(opt != null) {
EscherPropertyFactory f = new EscherPropertyFactory();
List props = f.createProperties( opt.getData(), 0, opt.getInstance() );
EscherSimpleProperty p = (EscherSimpleProperty)props.get(0);
//not sure if this heuristic "works" in 100% of cases
if(p.getPropertyNumber() == 0x39F && p.getPropertyValue() == 1){
return true;
}
}
return false;
}
Actually, Slide.getShapes() should return correct instances of shapes and the "instanceof Table" approach should work.
This isn't yet finished, so use the hack above.
Yegor
> Hi,
>
>
>
> I'm trying to read all shape from a PPT-File and cast them into there
> specific type.
>
>
>
> Can anyone tell my how to find out if there is a table in a shape or if a
> shape is a table.
>
>
>
> Thanks a lot
>
> Thorsten
>
>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org