Work with MS Office in ADF

cancel
Showing results for 
Search instead for 
Did you mean: 

Work with MS Office in ADF

kasper
Partner
3 0 3,438

This blog is about how to easily implement an offline edit in word in ADF. When we show ADF to our clients they all immediately want to switch from share. We think this is not strange however there are ofcourse some things that are less default in ADF than in share. For example the edit in office option is not (yet) in the handlers. 

So what we're trying to achieve is a simple "open in office" button anywhere. For example in the document list content actions.

Therefore we need to know something about how office works and how share in combination with office works. It consists of basically 4 steps.

  1. Check out
  2. Open
  3. Save
  4. Check in

But before these steps we need to know the link to the document. Alfresco provides such a link via Alfresco Office Services. We can obtain this link by the following code example, the structure always is the same, only the noderef and the host are different, take note that entry is a node entry.

 openInOffice(entry) {
    let filepath = entry.path.name;
    let position = filepath.split('/', 2).join('/').length;
    // remove first part that is not needed
    filepath = filepath.slice(position) + '/' + entry.name;
    let url = this.ecmHost + '/alfresco/aos' + filepath;
}
    ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Once the link is in place the fun can start. We basically need to open the link and the file will show up.

Module

But this is kind of a lot of work, therefore we created a simple module that can do all of this for you. Only the ECMHost and the document reference need to be provided. 

Just install the incentro-adf-msoffice-module.

Install via npm.

npm install --save incentro-adf-office-module
‍‍‍

Include the module in your angular module

@NgModule({
    imports: [
        IncentroOfficeModule,
        ...
    ]
})‍‍‍‍‍‍‍‍‍‍‍‍

To use the service add it to your component and call the function with a MinimalNodeEntry and the ECM Host.

@Component(...)
export class ExampleComponent {
  constructor(private officeActionsService: OfficeActionsService,
              private appConfigService: AppConfigService) {
   
  }
 
  openInOffice(event) {
    const ecmHost = this.appConfigService.get('ecmHost');
    this.officeActionsService.editOnline(event.value.entry, ecmHost);
  }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Once this is in place you should be able to open the file in word directly from your content list. See this Alfresco Tech Talk for more detailed information on this subject.