Free Support Forum - aspose.com

Table iteration order

hi,

In my pptx file there are three tables in one slide. During iteration, the tables are retrieved in the order they are created; not in the order they appear in the slide. Could you please suggest a solution ?

regards,

Sheeba

Hi Sheeba,


I suggest that you may use AleternativeText property to set the user defined name for the table and identify the tables on the basis of that inside shape collection. Please visit this documentation link for your further reference. Please share with us, if you still feel any issue.

Thanks and Regards,

Thanks for the reply.

The suggested link is not a solution to my problem. Because the file might not be created by us. Any other idea?

Regards,

Sheeba

Hi Sheeba,


If you are even creating presentation using Aspose.Slides even ShapeEx.AlternativeText property can be employed. When you will be creating your table then also set a user defined name for that table as well using AlternativeText property and that you may use for your further reference when you access that table again. Hope it clears the concept.

Thanks and Regards,

I am not supposed to modify the tables in the input file. Just extract details. Speed is also a constraint.

Hi Sheeba,


I regret to share that the use of AlternativeText property was an appropriate solution that can be opted. I don’t feel there is any speed related issue in it by verifying the shape based on AlternativeText property. However, as you have mentioned that you cannot modify the input table so the option of AlternativeText property is of no use for you. I have another workaround for you that is a little weird but can prove effective for you. I suggest that you identify the shapes on the basis of position on the slide. However, in order to use this approach you must be aware of the fact that your desired table is located at which position or approximate area of slide. This way whenever you will traverse through the shapes then based on its position you may tell that this is table X for you. I will still say that this may or may not work for you but the appropriate and effective way is still using AlternativeText property.

Many Thanks,

:-(

No.... I can't assume the layout of input file.

I wonder who is concerned with the tables in the order they are created. Getting the tables as listed will be more useful, I think. Is it difficult to achieve?

Hi Sheeba,

I regret to share that there is no other option available in this regard. Moreover, if one is interested in identifying some shape they must be identified through unique criteria. One of then is using AlternativeText to set unique name for shape. Other is to identify shapes order on the basis of position by your self. Another work around that you may try using is to identify the shapes based on contents inside table. Lets assume if you have 4 tables on the slide and each table may have some unique column that may not be present in other table. You can then identify the table on the basis of the unique column.

Thanks and Regards,

Okay, I understand.

I would like to use the second option of your suggestion, i.e identify shapes order on the basis of position. Could you please give me the details in this regard?

Thanks & Regards,

Sheeba

hi Mudassir,

I could iterate tables in the order of position on slide.

Thank you very much for your advice.

Regards,

Sheeba

Hi Sheeba,


That is really nice. It will be really appreciable if you may please share your work in this thread for future references. Please share if I may help you further in future.

Thanks and Regards,

hi mudassir,

please find the sample code below.

regards,
sheeba

private void parseTables() {
// ******* some code here to open document and get slides *********
ArrayList tables = new ArrayList();
// begin iterate shapes in slide
int nX = (int) shape.getX();
int nY = (int) shape.getY();
PageTableInfo objPageTableInfo = new PageTableInfo();
//fill objPageTableInfo with the cell contents.
tables.add(new TableInfo(nX, nY, objPageTableInfo));
// end iteration
Collections.sort(tables, tables.get(0));
}

class TableInfo implements Comparator {
int m_nX;
int m_nY;
// PageTableInfo - a user defined class that holds text from table.
PageTableInfo m_table;
public TableInfo() {
m_nX = 0; m_nY = 0; m_table = new PageTableInfo();
}
public TableInfo(int x, int y, PageTableInfo info) {
m_nX = x;
m_nY = y;
m_table = info;
}
public int getX() {
return m_nX;
}
public int getY() {
return m_nY;
}
public PageTableInfo getTable() {
return m_table;
}

@Override
public int compare(Object o1, Object o2) {
int ret = 0;
TableInfo tmp1 = (TableInfo) o1;
TableInfo tmp2 = (TableInfo) o2;
if (tmp1.getY() <= tmp2.getY()){
ret = 0;
}
else {
ret = 1;
}
return ret;
}
}