+ Start a Discussion

How to handling word Document in salesforce?

Hi Everyone,

How to read Word Document in the Apex class.Here i was trying to write a apex class to fetch the data as shown in below code.if anyone know how to fetch data and read data please help me.

Apex Class:

public class TestFormController {
    public String comment{get;set;}
    public String content{get;set;}
    public String ContactName{get;set;}
public void fetchData()
        System.debug('testForm called');
        String content;
        List<Folder> folderList = [Select id, name from Folder where name = 'Templates' Limit 1];
        if(folderList.size() > 0){
            List<Document> documentList = [SELECT id, name, body from Document where folderid =:folderList[0].id and name = 'Test Form'];
            if(documentList.size() > 0){
              content =  documentList[0].body.toString(); // while run the visual force here i was blocking mainly.
            Content = Content.replaceAll('@ContactName', 'Test');
        }catch(Exception e) 
            System.debug('Exception >>> ' + e.getMessage());

Visual Force Page:

<apex:page contentType="application/ms-word#test Form.doc" controller="TestFormController" action="{!fetchData}">
    <apex:Form >
        <apex:pageBlock >
            <apex:outputLabel value="documentList" style="margin:0px 0 0 120px;font-size:22px;color:blue;"/>-->
            <apex:outputText value="{!content}" escape="false">

Please if anyone know how to fetch data please help me.

Thanks In advance,
ANUTEJANUTEJ (Salesforce Developers) 
Hi Rajubalaji,

>> https://salesforce.stackexchange.com/questions/266916/how-to-read-text-content-of-ms-word-files-in-salesforce

The above link has a similar implementation that is identical to your requirement, can you try checking the above link once and tests answer in above link?

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.