Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is CTP, CTTbl classes (objects) in Apache POI?

I'm trying to understand some parts of Apache POI. For instance, i;m trying to get text (or table, etc.) from an existing docx file. For example there is a method getParagraph(..CTP p) in XWPFDocument:
It returns "a paragraph with a CTP class p". But what is CTP class? I've looked inside the xml structure of the document, but didn't find anything similar. As a result i don't know how to call a mthod in the first place. There is also a method getTable(CTTbl CTTbl) for the same XWPFDocument, that returns "a table by its CTtbl-Object.

It seems there is a CP* something for every part/type of data inside ooxml documents, so i'd like to understand how to work with them. Moreover, from the documentation, it seems that those methods are the only direct way to get elements without sticking them into collection, or guessing their position.

like image 448
Emptyfruit Avatar asked Aug 29 '14 19:08

Emptyfruit


1 Answers

The CTx classes are XMLBeans wrappers. They are auto-generated from the published OOXML specification XML Schema files.

If the xml element in the file is a p one, then the resulting XMLBeans wrapper for OOXML will be CTP. If it's table, then it'll be CTTable. The namespace of the xml element will make onto the class's package, so if you have two different elements with the same local name but different namespaces, that's how you'll be able to work out which one you want.

If you have a choice, don't work with the CT classes. They are low level, and require you to know about the structure and format of the underlying file format. They are normally only required for advanced use cases.

Almost everything you will want to do for a common use case will be possible with the Apache POI usermodel wrapping classes, use only those if you can.

like image 187
Gagravarr Avatar answered Sep 24 '22 18:09

Gagravarr