cancel
Showing results for 
Search instead for 
Did you mean: 

Word document contents blank

Former Member
0 Kudos

Hi ,

I have made an application where I am using OfficeUIElement,below is the code which I have written in the source function(fillNode) of the view context which will hold document content in binary format.I am getting the output in the sense that the Office element comes integrated in the view but it does not read the data of the file location which i have specified,the output is blank.

Any inputs on what I am missing?

IWDAttributeInfo attrInfo =

wdContext.nodeDocumentSourceNode().getNodeInfo().getAttribute("DocumentContent");

ISimpleTypeModifiable simpleType = attrInfo.getModifiableSimpleType();

IWDModifiableBinaryType binaryType =

(IWDModifiableBinaryType) simpleType;

binaryType.setMimeType(new WebResourceType("doc", "application/msword", false));

IPrivateWordCompView.IDocumentSourceNodeElement element = node.createDocumentSourceNodeElement();

try {

byte[] bytes = getBytesFromFile(new File("http://172.31.69.170:84/motivation.doc"));

element.setDocumentContent(bytes);

}

node.addElement(element);

public static byte[] getBytesFromFile(File file)

throws IOException

{

FileInputStream is = new FileInputStream(file);

long length = file.length();

byte[] bytes = new byte[(int)length];

long bytesRead = is.read(bytes);

if (bytesRead < length)

{ throw new IOException("Could not completely read file "+file.getName());

}

is.close();

return bytes;

}

public void wdDoInit()

{

WDOfficeControlMethods.showDocument(this.wdThis.wdGetAPI(),"OfficeControl1");

}

Maybe I am missing a small thing,so any suggestions are welcome.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

The problem is here

<i>new File("http://172.31.69.170:84/motivation.doc")</i>

Try to use URL / URLConnection class -- file object could not load content by HTTP

VS

Former Member
0 Kudos

Hi Valery,

Thx for ur reply.I would really appreciate if you could elaborate a bit more on your suggestion.Actually I tried to load the contents of a file in my local C drive but still the office control did not get the contents of the file.

Former Member
0 Kudos

I found only 2 differents so far with my own code:

1. Modifying attribute is called before "ShowDocument" invocation in wdDoInit (the sequence is not obvious from your sample)

2. I use binaryType.setMimeType( WDWebResourceType.DOC ) instead of custom resource type

VS

Former Member
0 Kudos

I am having only "ShowDocument" lind wdDoInit(),The supply function(fillNode) specified for the context node is used to load the document contents of the word file in binary format to context attribute.My understanding is that the supply function should load the contents of the file before I call "ShowDocument" in wdDoInit().

Also is there any problem with the way I am reading the contents of the file and returining the bytes.

Now I am using the local directory file for displaying the contents but still I am getting blank output:

byte[] bytes = getBytesFromFile(new File("C://motivation.doc"));

Former Member
0 Kudos

Hi Mandeep,

Check if you have named your UI element something else other than OfficeControl1 as in this method:

WDOfficeControlMethods.showDocument(this.wdThis.wdGetAPI(),

"OfficeControl1");

Somehow this doesn't throw any exception you specify the wrong element ID. Could make such an error when going directly by the example.

Answers (0)