cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

How to add the attribute to Word Document which is available on Server

mlokesh-2
4-Participant

How to add the attribute to Word Document which is available on Server

Hello Windchill Gurus,

I am looking for a solution to add attributes (to Word Document) of documents available on the Server without downloading them into client (local machine). Client wants to have 4 attributes (not the IBAs, but the attributes to a Microsoft Word Document) on all the documents currently available on the System. These 4 attributes are in-fact driven from the IBAs available in those documents, but needs to be updated.

Thanks in advance for your help.

Thanks,

Mahesh KL

4 REPLIES 4

Hi, Mahesh!

I am not actually understand what is your question:

-How to modify primary attachment

-How to get attributes from Object

- ...

Look this: Apache POI - the Java API for Microsoft Documents

It gives you tools for working with MS Office documents by java code.

Hello Anton,

Thanks for Reply.

I have shown an example document properties. Likewise, I need to create 5 more properties and update their values in the server. These documents are primary content of the WTDocuments in the system.

I was trying to find out a way to update them. Do I need to download the Primary content before using the Apache POI tools? Or they can apply on content on the server directly?

Word Document Properties.png

Thanks,

Mahesh KL

Hi!

I have never worked with the MS Word attributes.

You can get primary content as the byte aaray. For exemple you can create the servlet that will handle your files. Algorithm (obj is Persistable):

1. Check out object

ex 1.1:

Folder myFolder = WorkInProgressHelper.service.getCheckoutFolder();

  CheckoutLink checkout_lnk = WorkInProgressHelper.service.checkout((Workable)obj, myFolder, "workingCopy");

  obj = checkout_lnk.getWorkingCopy();

  LWCNormalizedObject lno = new LWCNormalizedObject(obj, null, Locale.getDefault(), new UpdateOperationIdentifier());

---

2.. Get primary attachment

ex 2.1:

public static byte[] getContentBytes(Object obj, ContentRoleType contentType)

  {

  byte[] bytes = null;

  try

  {

  bytes = ContentHolderHelper.getContentBytes((ContentHolder)obj, 1024, "", contentType);

  } catch (WTException e) {e.printStackTrace();}

  return bytes;

  }

3. Modify content via Apache POI (use LWCNormalizedObject for getting object attributes)

ex 3.1:

public static String getObjectAttrValue(Object obj, String attrName)

  {

  LWCNormalizedObject nobj=null;

  try

  {

  nobj = new LWCNormalizedObject((Persistable)obj, null, null, null);

  nobj.load(attrName);

  return (String)nobj.get(attrName);

  }

  catch (WTException e) {e.printStackTrace();}

  return null;

  }

---

4. Refresh primary

ex 4.1:

ContentHolderHelper.updateContents(wtd, byteArray, ContentRoleType.PRIMARY);

---

5. Check in object

ex 5.1:

WorkInProgressHelper.service.checkin((Workable)obj, null);

UPD: Apache poi is the part of Windchill API.

Announcements


Top Tags