ILGDRM
asked on
How to get word document content
Hi ,
After opening the word document through the following code we can get the Text content of Word Document.
IDispatch* pDispRange = oDocument.GetContent();
Range objRange(pDispRange);
AfxMessageBox(objRange.Get Text());
How to get the entire word document content ( text, images and tables) in Byte Array.
After opening the word document through the following code we can get the Text content of Word Document.
IDispatch* pDispRange = oDocument.GetContent();
Range objRange(pDispRange);
AfxMessageBox(objRange.Get
How to get the entire word document content ( text, images and tables) in Byte Array.
ASKER
Thanks for reply
Actually I want to retrive document content on DocumentOpen Event. On the fly i want to decrypt the content and assign this content to _Document Ptr so that user can access the Decrypted Content.
On DocumentBeforeSave I want to encrypt the content and store into the file.
Actually I want to retrive document content on DocumentOpen Event. On the fly i want to decrypt the content and assign this content to _Document Ptr so that user can access the Decrypted Content.
On DocumentBeforeSave I want to encrypt the content and store into the file.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for Approaches provided by you.
Can you provide sample source code for Suggested approaches.
Can you provide sample source code for Suggested approaches.
Alternatively, you can yse VBA. VBA is better suited for Office Automation. In VBA, you can access the document content easily:
ActiveDocument.Content
ActiveDocument.Content
ActiveDocument.Content will give a Range object. You can use that object to iterate over images, text, tables etc. but there is no easy way to convert it into a byte array.
Before we embark upon a particular option can you please provide a little insight into your requirements?
What exactly do you want to achieve by enc/dec a word document?
What were your initial thoughts that made you try enc/dec the contents in open/close handlers?
When you enc a document, is it necessary that the resultant be also a word doc?
Before we embark upon a particular option can you please provide a little insight into your requirements?
What exactly do you want to achieve by enc/dec a word document?
What were your initial thoughts that made you try enc/dec the contents in open/close handlers?
When you enc a document, is it necessary that the resultant be also a word doc?
ASKER
Hi Ambience,
What exactly do you want to achieve by enc/dec a word document?
What were your initial thoughts that made you try enc/dec the contents in open/close handlers?
->
My requirement is I want to protect ( Encrypt ) the output generated by word document (i.e. *.doc).
I want to encrypt it immedietly after storing document on disk(On DocumentSave event). Same encrypted document I want to decrypt on the fly when user tries to open it(On DocumentBeforeOpen event). I want to encrypt entire document or content irrespective of it's data type. How to achive
Option 2 suggested by you i.e. "Consider encrypting the whole document, rather than contents of the doc. You can encrypt the file after it is written by Word and conversely, decrypt before feeding it to word."
When you enc a document, is it necessary that the resultant be also a word doc?
-> Not Necssary
What exactly do you want to achieve by enc/dec a word document?
What were your initial thoughts that made you try enc/dec the contents in open/close handlers?
->
My requirement is I want to protect ( Encrypt ) the output generated by word document (i.e. *.doc).
I want to encrypt it immedietly after storing document on disk(On DocumentSave event). Same encrypted document I want to decrypt on the fly when user tries to open it(On DocumentBeforeOpen event). I want to encrypt entire document or content irrespective of it's data type. How to achive
Option 2 suggested by you i.e. "Consider encrypting the whole document, rather than contents of the doc. You can encrypt the file after it is written by Word and conversely, decrypt before feeding it to word."
When you enc a document, is it necessary that the resultant be also a word doc?
-> Not Necssary
Well then the simplest that I can recommend is using the EncryptFile API provided by windows.
BOOL bRes = EncryptFile(szPathToWordDo c);
where szPathToWordDoc is the path to the file created by word. Similarly you can use the DecryptFile function to do the reverse (before opening the document).
Foe more info see:
http://msdn.microsoft.com/en-us/library/aa364021(VS.85).aspx
http://msdn.microsoft.com/en-us/library/aa363903(VS.85).aspx
Hope this helps ...
BOOL bRes = EncryptFile(szPathToWordDo
where szPathToWordDoc is the path to the file created by word. Similarly you can use the DecryptFile function to do the reverse (before opening the document).
Foe more info see:
http://msdn.microsoft.com/en-us/library/aa364021(VS.85).aspx
http://msdn.microsoft.com/en-us/library/aa363903(VS.85).aspx
Hope this helps ...
ASKER
Hi ,
Thanks for Reply!!
Suggested solution is possible only if intented document is closed ( in Off Line Mode ).
Actually my requirement is
I want to retrive document content or whole document on DocumentOpen Event or while opening Encrypted Document. And while saving or on DocumentBeforeSave I want to Encrypt the Document Content or Whole document. While Accessing the File ( Document ) on Hard Disk it should be in encrypted format. When Word application try to access encrypted file content should be in decrypted format on the fly.
Thanks for Reply!!
Suggested solution is possible only if intented document is closed ( in Off Line Mode ).
Actually my requirement is
I want to retrive document content or whole document on DocumentOpen Event or while opening Encrypted Document. And while saving or on DocumentBeforeSave I want to Encrypt the Document Content or Whole document. While Accessing the File ( Document ) on Hard Disk it should be in encrypted format. When Word application try to access encrypted file content should be in decrypted format on the fly.
Strange, the code snippet that you originally posted
IDispatch* pDispRange = oDocument.GetContent();
Range objRange(pDispRange);
AfxMessageBox(objRange.Get Text());
suggested something different. It appeared as though you have access to the file and Automate word to open the file. In that case I thought that you may insert an extra decryption step.
Is it ok for you to insert VB script macros to the document that you are trying to encrypt? Or do you want to use the C++ application to encrypt the doc?
IDispatch* pDispRange = oDocument.GetContent();
Range objRange(pDispRange);
AfxMessageBox(objRange.Get
suggested something different. It appeared as though you have access to the file and Automate word to open the file. In that case I thought that you may insert an extra decryption step.
Is it ok for you to insert VB script macros to the document that you are trying to encrypt? Or do you want to use the C++ application to encrypt the doc?
ILGDRM,
As I said earlier, using VBA is my choice for this problem. Are you open to using VBA. If yes, you can get the content of the document easily (see may earlier post) and there are ways how you can encrpyt the data from within. See the below link:
http://www.webace.com.au/~balson/InsaneExcel/Encryption.htm
As I said earlier, using VBA is my choice for this problem. Are you open to using VBA. If yes, you can get the content of the document easily (see may earlier post) and there are ways how you can encrpyt the data from within. See the below link:
http://www.webace.com.au/~balson/InsaneExcel/Encryption.htm
ASKER
Hi
I want to use the C++ Application to Encrypt / Decrypt the document ( COM Addin ).
If possible please provide the sample source code.
I want to use the C++ Application to Encrypt / Decrypt the document ( COM Addin ).
If possible please provide the sample source code.
HI
Did you ever get this to work? I am currently trying to achieve the same thing
Did you ever get this to work? I am currently trying to achieve the same thing
You can use the standard file function.