简体   繁体   中英

How to Fetch Task Notes from MS Project File (.mpp) if an Image/text is Attached to it

I have been trying to fetch Notes attached to a task using the MPXJ library,using the method

getNotes()

from the class

net.sf.mpxj.Task

However the return type of the method is a String, and you can even insert Images and other Files as notes to the Task. My question is How Would it be possible for me to retrieve an image attached to the task.

在此处输入图片说明

Also if I attach a plain text note to the Task eg. in this case the note is "This is Task 200"

在此处输入图片说明

It is retrieved as the following Text

{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang16393{\fonttbl{\f0\fnil\fcharset0 Segoe UI;}} {\*\generator Riched20 15.0.4567}{\*\mmathPr\mwrapIndent1440 }\viewkind4\uc1 \pard\f0\fs20 This is Task 200\par }

I would be great is somebody could give a feedback on this.

Your starting point is the MPPReader class. The method setPreserveNoteFormatting allows you to control whether you get plain text or the RTF. You will need to retrieve the RTF in order to extract any embedded onjects:

MPPReader reader = new MPPReader();
reader.setPreserveNoteFormatting(true);
ProjectFile file = reader.read("/path/to/my/file.mpp");

There is a class distributed with MPXJ called RTFEmbeddedObject which implements a mechanism to extract the raw data for any objects embedded in the RTF produced by MS Project. Let's assume we have some notes attached to task 1, which contain embedded objects.

Task task = file.getTaskByID(1);
String notes = file.getNotes();
List<List<RTFEmbeddedObject>> list = RTFEmbeddedObject.getEmbeddedObjects(notes);

The data returned is a list of lists... not great, but it works. The first list contains one entry per embedded object in the notes. Each list entry is composed of a list of blocks with a couple of flags (of unknown significance) and a block of binary data.

In the examples I've come across so far, you can expect to see pairs of blocks. The first block will contain a text label, detailing the type of the data that follows, and the second block will contain the raw data for the embedded object.

Typically there are four blocks per embedded object, two blocks to hold the raw data for the object itself, and two blocks representing the metafile preview image of the embedded object.

Have a look at the unit test MppEmbededTest with a debugger - you'll be able to see the embedded object data being read from an example file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM