Hello,
Thank you for your feedback.
Our Spire.Doc supports getting the shape names, but the method has not yet been published. I have submitted the requirment to our Dev team, once the method is available, I will inform you.
As for getting the text of shape, please refer to the code below. If there is still any question, please share your sample Word file to help us have a better investigtation. You could attach it here or send to us via email (
[email protected]). Thanks in advance.
- Code: Select all
Document doc = new Document();
doc.loadFromFile("input.docx");
for (Section section : (Iterable<Section>)doc.getSections()) {
for (int i = 0; i < section.getParagraphs().getCount(); i++) {
Paragraph para = section.getParagraphs().get(i);
for (int j = 0; j < para.getChildObjects().getCount(); j++)
{
DocumentObject obj =para.getChildObjects().get(j);
//if the obj is shape object
if (obj instanceof ShapeObject)
{
ShapeObject shape = (ShapeObject) obj;
String content = "";
//get the child objects of the shape
for (int c =0; c < shape.getChildObjects().getCount(); c ++){
//get the document object type of the child object
DocumentObjectType doType = shape.getChildObjects().get(c).getDocumentObjectType();
//If doType is paragraph
if (doType.equals(DocumentObjectType.Paragraph)){
Paragraph paragraph = (Paragraph)shape.getChildObjects().get(c);
//get the text
content += paragraph.getText();
}
}
System.out.println(content);
}
}
}
}
Sincerely,
Annika
E-iceblue support team