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

1

12

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.

Violence answered 29/8, 2014 at 19:55 Comment(0)
H
14

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.

Heymann answered 29/8, 2014 at 23:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.