MICROSOFT.OFFICE.INTEROP.WORD - Object reference not set to an instance of an object

1

I'minneedofhelpwiththisproblemusingMicrosoft.Office.Interop.Word.Detail:runningtheapplicationinvisualstudioitworksnormally,withnoerror,however,ifIplayinIIS,itappearsthiserror.Beforeit,IhadproblemwithCOMpermission,Ichangedthepermissionsandnowthiserrorappears.LookatthepicturesthatshoweverythingI'vedonesofar.Hereissomeinformationaboutwhathasalreadybeendone.

1-IhaveaddedIIS_IUSRSandNETWORKSERVICESpermissionsonspecificCOMaccesspermission(inthecaseofMicrosoftWord97-2003Document);

2-TheCOMidentityisdefinedasaninteractiveuser;

3-ThereisaMicrosoft.Office.Interop.Wordreferenceintheproject;

4-TheMicrosoft.Office.Interop.Wordexistsonthecomputer,thatis,Officeisinstalled(64bitversion).Theoperatingsystemis64bitaswell.

Ineedalottosolvethisproblem,becausetheprojectwasdeveloped-morethan3months-ontopofMicrosoft.Office.Interop.Word,whereIusetheconversiontoPDFandalso,IuseamethodtomodifythefilebeforeconvertingittoPDF.

CODE

PDFconversionmethod

publicstaticvoidConverterEmPdf(stringentrada,stringsaida){varmissing=Type.Missing;varappWord=newMicrosoft.Office.Interop.Word.Application();varwordDocument=appWord.Documents.Open(entrada);wordDocument.ExportAsFixedFormat(saida,Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF);((Microsoft.Office.Interop.Word._Document)wordDocument).Close(refmissing,refmissing,refmissing);}

Methodtochangedocument

publicstaticvoidInserirNumero(objectfileName,objectsaveAs,intnumero){objectmissing=System.Reflection.Missing.Value;varwordApp=newMicrosoft.Office.Interop.Word.Application();if(!File.Exists((string)fileName))return;objectreadOnly=false;objectisVisible=false;wordApp.Visible=false;varaDoc=wordApp.Documents.Open(reffileName,refmissing,refreadOnly,refmissing,refmissing,refmissing,refmissing,refmissing,refmissing,refmissing,refmissing,refisVisible,refmissing,refmissing,refmissing,refmissing);aDoc.Activate();LocalizarESubstituir(wordApp,"<numerodocumento>", numero);
        aDoc.SaveAs(ref saveAs, ref missing, ref missing, ref missing,
            ref missing, ref missing, ref missing, ref missing,
            ref missing, ref missing, ref missing, ref missing,
            ref missing, ref missing, ref missing, ref missing);
        ((Microsoft.Office.Interop.Word._Document)aDoc).Close(ref missing, ref missing, ref missing);  
    }

Find and replace method used in the previous method

private static void LocalizarESubstituir(Microsoft.Office.Interop.Word._Application wordApp, object findText, object replaceWithText)
    {
        var missing = Type.Missing;

        object matchCase = true;
        object matchWholeWord = true;
        object matchWildCards = false;
        object matchSoundLike = false;
        object nmatchAllWordForms = false;
        object forward = true;
        object format = false;
        object matchKashida = false;
        object matchDiacritics = false;
        object matchAlefHamza = false;
        object matchControl = false;
        object replace = 2;
        object wrap = 1;

        if (replaceWithText.ToString().Length < 250)
        {
            wordApp.Selection.Find.Execute(ref findText, ref matchCase,ref matchWholeWord, ref matchWildCards, ref matchSoundLike,
                                          ref nmatchAllWordForms,ref forward, ref wrap, ref format, ref replaceWithText, ref replace,  ref matchKashida, ref matchDiacritics, ref matchAlefHamza, ref matchControl);
        }
        else
        {
            wordApp.Application.Selection.Find.Execute(ref findText,
        ref missing,
        ref missing,
        ref missing,
        ref missing,
        ref missing,
        ref missing,
        ref missing,
        ref missing,
        ref missing,
        ref missing,
        ref missing,
        ref missing,
        ref missing,
        ref missing);
            ((Microsoft.Office.Interop.Word._Document)wordApp).Application.Selection.Text = (string)replaceWithText;
        }
    }

IMAGES OF EVERYTHING YOU HAVE DONE TO TRY TO SOLVE THE PROBLEM

    
asked by anonymous 27.04.2015 / 17:23

0 answers