Open word file by Delphi

Asked

Viewed 547 times

2

I have a system that integrates with MS-Word I can do almost everything on it, just can’t open the document and leave it as read-only so that the user can not make modifications. currently my code is so:

//Cria objeto principal de controle
try
  with OleContainer do
  begin
    if OleObjectInterface <> Nil then
    begin
      DestroyObject;
    end;
    //Nome do arquivo usado para abrir o arquivo de entrevista
    vNomeArquivo  := DM.tbParamPASTA_BD.AsString+'\MODELOS\'+DM2.qryConsultasMODELO.AsString;   
    try
      OleContainer.CreateObjectFromFile(vNomeArquivo, OF_READ);
      OleContainer.DoVerb(ovShow);
      Perform(WM_LBUTTONDBLCLK, MK_LBUTTON, 0);
    except
      //Fechar o arquivo
      DestroyObject;
    end;
  end;
finally
  Screen.Cursor := crDefault;
  OleContainer.TabStop := False;

end;

PS: I don’t want to open a document that has the attribute Readonly me I want to prevent the user from changing the document type Protected mode Unrestricted

1 answer

2


We don’t use the olecontainer, but for our needs here when we need to leave the document readonly for the user we use the following line..:

OleContainer.CreateObjectFromFile(vNomeArquivo, false);
OleContainer.DoVerb(ovShow);
OleContainer.OleObject.Protect(3);
Perform(WM_LBUTTONDBLCLK, MK_LBUTTON, 0);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.