We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Retrieving Table cell data and Image at the same time to a single entity

Hi, I have a problem in retrieving image and the data in the table cells at the same time which belongs to a single entity. I can retrieve the data from the cells but not the image source. It does not go into the (else if statement). I have also tried using the code in the programmer guide. I could retrieve the image but not together with the table cells. I had attached a sample copy of the document that I need to retrieve the data from. Could anyone help me? Thanks in advance!

The code below is the code for opening and retrieving the data from the document:
Note: Dish is my object class. I want to save the dish image and its data into the dish class and using dishList to save the dish and return the dishList.

public static ArrayList openDishDoc(String fileName) throws Exception {
InputStream stream = new FileInputStream(fileName);
Document doc = new Document(stream);
stream.close();
ArrayList dishList = new ArrayList();
Section section = doc.getSections().get(0);
Body body = section.getBody();
for (Node node = body.getFirstChild(); node != null; node = node.getNextSibling()) {
Dish dish = new Dish();
if (node.getNodeType() == NodeType.TABLE) {
Table table = (Table) node;
for (int i = 0; i < table.getRows().getCount(); i++) {
Row row = (Row) table.getRows().get(i);
if (row.getFirstCell().toTxt().trim().equalsIgnoreCase(“dish id:”)) {
dish.setDishId(Integer.parseInt(row.getFirstCell().getNextSibling().toTxt().trim()));
} else if (row.getFirstCell().toTxt().trim().equalsIgnoreCase(“dish name:”)) {
dish.setDishName(row.getFirstCell().getNextSibling().toTxt());
} else if (row.getFirstCell().toTxt().trim().equalsIgnoreCase(“dish type:”)) {
dish.setType(row.getFirstCell().getNextSibling().toTxt());
} else if (row.getFirstCell().toTxt().trim().equalsIgnoreCase(“dish price:”)) {
dish.setPrice(Double.parseDouble(row.getFirstCell().getNextSibling().toTxt()));
} else if (row.getFirstCell().toTxt().trim().equalsIgnoreCase(“prepared by:”)) {
dish.setPreparedBy(row.getFirstCell().getNextSibling().toTxt());
} else if (row.getFirstCell().toTxt().trim().equalsIgnoreCase(“description:”)) {
dish.setDescription(row.getFirstCell().getNextSibling().toTxt());
}
}
} else if (node.getNodeType() == NodeType.SHAPE) {
Shape shape = (Shape) node;
dish.setImage(shape.getImageData().getSourceFullName());
}
if (dish.getDishId() != 0) {
dishList.add(dish);
}
}
return dishList;
}

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. You cannot get Shape because it is not a direct child of Body. Shape can be a child of Paragraph or SmartTag. Please follow the link to learn more about Aspose.Words Document object Model:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/object-model-overview.html

Also, you can use DocumentExplorer (Aspose.Words demo application) to investigate structure of documents.

Please let me know if you need more assistance, I will be glad to help you/

Best regards.