Stop select and copy of excel sheet in protect mode

R

Rakesh

Hi All,

I have a SDI application developed using MFC Appwizard.
This is an office automation application and MS Excel is automated in this
application.
In this application I have shown an excel file in right pane (client view)
of the application.
I want to show my excel files in right pane in protected mode such that user
can only view the files can not copy and write.
I protect the excel file as :


oWSheet = oWBook.GetActiveSheet();
oWSheet.Protect(COleVariant(_T("password")),covTrue,covTrue,covTrue,covTrue,

covOpt,covOpt,covOpt,covOpt,covOpt,covOpt,covOpt,covOpt,
covOpt,covOpt,covOpt);
oWSheet.SetEnableSelection(-4142);
oWBook.SaveAs(COleVariant(_T("c:\\test.xls")),covOptional,COleVariant(_T("")
),COleVariant(_T("")),
covFalse,covFalse,1,covOptional,covFalse,covOptional,
covOptional,covOptional);
oWBook.Save();
//*****File is protected and can not be selected, copied******/
oWBook.Close(covOptional,covOptional,covOptional); //*****Problem occurs
after this statement******/
oWBook.ReleaseDispatch();
oWBooks.Close();
oWBooks.ReleaseDispatch();
oApp.Quit();
oApp.ReleaseDispatch();

Problem occurs at this statement.As file closed its protection lost in such a way that file can not be
written and can be selected and copy. I want to stop this.
Before closing the file as I saw in MS Excel (visible mode) file is
completely protected and can not be selected, copy and written.

Reply ASAP.

With Best Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top