Skip to Content
We can use Office UI Element to work with office documents. I would like to explain with a very simple example.Lets take a scenario where you want to open and close a document in WebDynpro

Pre-requisite :Place the document that you want to open in mimes folder of the WebDynpro project

Follow the steps below

1. Create a OfficeControl on the view

2. Create a valueAttribute in the context and set the type to binary

3. Set the datasource of the officecontrol to the above valueattribute

4. Create three buttons labled as “New” , “Open” and “Close” as shown below

5. Write the following code in the wdDoInit() method. The following code will read the file that we want to open , convert the file to byte array and set the byte array to the value attribute which is a datasource to the office UIElement



6. Declare the following as public variables

  • public IWDIOSFactory factoryInstance;
  • public IWDIOSDocument documentInstance;


In the above code getBytesFromFile() is method which returns byte array. Find the code for the same.

Now we have the context ready and we set the context to the existing document .We will place a button with label “Open” and the requirement is when you click on the “Open” button it should show the document in the Office UIElement.Paste the following code in the “Open” button action handler



Now create one more button labled as “New” ,on click of this button the officeDocument control should open a new document.So to do this paste the following code in the action handler of “New” button



Create a button with label “Close” and write the following code in the Close action handler



The final application will look like the following

image

In my next web log we will see how we can use OfficeUIElement with FileUpload control so that user can select and open the documents dynamically

To report this post you need to login first.

6 Comments

You must be Logged on to comment or reply to a post.

    1. Anilkumar Vippagunta Post author
      Hi Maarten,

      You are right.But currently there is no sample application available in SDN and there some postings in SDN on how to use the control.
      One more reason is ,i would like to explain how we can use Office along with Fileupload UIElement.Explaining this in one weblog will be difficult so i’ve started with simple Officecontrolusage and divided the blog into two.

      Regards,Anilkumar

      (0) 
  1. juan rios
    Hello.

    I followed this example and the app is running perfectly, great post. The next step that I’m trying is to save de loaded file to the server. Sincerely I’ve tried to do so but I haven’t found the way to save the file that the user uploads to the server.

    I really hope that you can help me.

    Thanks in advance.

    (0) 

Leave a Reply