Aspose com.aspose.words.Table StyleIdentifier

Is there a way to get All possible stylesidentifiers so that i can show them?

For instance i want to show all Tables styles in a dropdown menu, so that a user can choose a style for his/her tables in a document.

Hi there,

Thanks for your inquiry.

You can use the following code to find all table styles that are present inside a document:

for (Style style: doc.getStyles())
{
    if (style.getType() == StyleType.TABLE)
        System.out.println(style.getName());
}

Please note that this will not return all possible table styles, only the ones stored or used in the document.

If you require all table styles then it will most likely require some reflection. Please let us know if this is the case.

Thanks,

Well I actually need all styles that are compatible with tables. At the moment i did something simple like this:

public static Field[] getAllTableStyles() throws Exception
{
    Field[] fields = StyleIdentifier.class.getDeclaredFields();
    return fields;
}

I used reflection for this with “import java.lang.reflect.Field”

This gives me an array with all possible styles. I know this is probably not the correct way to handle this. It also gives me ALL possible styles but I’m only looking for styles compatible with tables. So I want to filter the styles like: BOOK_TITLE.

p.s. thanks for your quick reaction.

Hi there,

Thanks for this additional information.

Please try using the code below. It’s not very elegant, but it probably the quickest way of finding all table styles (other than embedding a document using all table styles and using first code example I gave).

public static ArrayList getAllTableStyles() throws Exception
{
    java.lang.reflect.Field[] fields = StyleIdentifier.class.getDeclaredFields();
    ArrayList tableFields = new ArrayList();
    Document doc = new Document();
    Table tempTable = new Table(doc);
    tempTable.ensureMinimum();
    for (java.lang.reflect.Field field: fields)
    {
        try
        {
            tempTable.setStyleIdentifier(field.getInt(null));
            tableFields.add(field);
        }
        catch (Exception e)
        {}
    }
}

If we can help with anything else, please feel free to ask.

Thanks,

Thanx, this is what I was looking for. I already made the same function, but the trick with the try catch just to see if its possible for a table is the solution to my problem. Like you said, it might not be the most elegant way, but it does the trick. Thanks.

Maybe just add functions like these to the API in the future? Or is there a reason not to add this?

Anyway, thanks again for the response.

Hi there

Thanks for your feedback.

Yes, we are constantly adding new functions to the API and we often expand the API based on the requests from customers. I have logged your request for this feature in our internal system. We will inform you as soon as there are any developments.

Thanks,