Thread View: borland.public.cppbuilder.nativeapi
3 messages
3 total messages
Started by Sara T.
Wed, 23 Apr 2003 16:23
Checking type in Microsoft Office Document
Author: Sara T.
Date: Wed, 23 Apr 2003 16:23
Date: Wed, 23 Apr 2003 16:23
11 lines
1373 bytes
1373 bytes
How can I know which type of Microsoft Office Document before openning ? Such as: 1. I have Microsoft Word named xxx.doc 2. I rename file xxx.doc to xxx.xls 3. How can I check that file xxx.xls has the original type in Microsoft Word ? Anybody has any idea or some part of API to handle like this ? Sara T.
Re: Checking type in Microsoft Office Document
Author: Remy Lebeau (TeamB)
Date: Wed, 23 Apr 2003 18:33
Date: Wed, 23 Apr 2003 18:33
15 lines
1439 bytes
1439 bytes
"Sara T." <sarana@infoquest.co.th> wrote in message news:3ea6be1f@newsgroups.borland.com... > 1. I have Microsoft Word named xxx.doc > 2. I rename file xxx.doc to xxx.xls > 3. How can I check that file xxx.xls has the original > type in Microsoft Word The only way would be to actually open the file and examine its data manually. You can go to http://www.wotsit.org to download spec sheets for the DOC and XLS file format. Gambit
Re: Checking type in Microsoft Office Document
Author: Damon Chandler (TeamB)
Date: Wed, 23 Apr 2003 19:46
Date: Wed, 23 Apr 2003 19:46
112 lines
3736 bytes
3736 bytes
Hi Sara,
> How can I know which type of Microsoft Office Document before openning ?
You might try accessing the document's Application Name property from its
Summary property set; this technique is described in MSDN Q186898...
http://support.microsoft.com/default.aspx?scid=kb%3ben-us%3b186898
Here's a rough code example; the function will return a string that contains
"Microsoft Word", "Microsoft Excel", etc...
#include <ole2.h>
AnsiString GetCmpdDocumentApp(
WideString filename
)
{
// will hold the document's application name
AnsiString AppName;
// open the compound document
IStorage* pStorage = NULL;
HRESULT hRes = StgOpenStorage(
filename.c_bstr(), NULL, STGM_READ |
STGM_SHARE_EXCLUSIVE, NULL, 0, &pStorage
);
if (FAILED(hRes))
{
throw EWin32Error("Cannot open compound document.");
}
try // acess the document's property set
{
IPropertySetStorage* pPropSet;
hRes = pStorage->QueryInterface(
IID_IPropertySetStorage,
reinterpret_cast<void**>(&pPropSet)
);
if(FAILED(hRes))
{
throw EWin32Error("Cannot access property set.");
}
try // access the Summary properties
{
IPropertyStorage* pProp;
hRes = pPropSet->Open(
FMTID_SummaryInformation, STGM_READ |
STGM_SHARE_EXCLUSIVE, &pProp
);
if(FAILED(hRes))
{
throw EWin32Error("Cannot access summary properties.");
}
try // read the Application Name property
{
// specify the property to retrieve
PROPSPEC prop_spec;
std::memset(&prop_spec, 0, sizeof(PROPSPEC));
prop_spec.ulKind = PRSPEC_PROPID;
prop_spec.propid = PIDSI_APPNAME; // application name
// read the property
PROPVARIANT prop_var;
hRes = pProp->ReadMultiple(1, &prop_spec, &prop_var);
if (FAILED(hRes))
{
throw EWin32Error("Error reading AppName property.");
}
// copy the application name
AppName = prop_var.pszVal;
// clean up
pProp->Release();
}
catch (...)
{
// clean up
pProp->Release();
throw;
}
// clean up
pPropSet->Release();
}
catch (...)
{
// clean up
pPropSet->Release();
throw;
}
// clean up
pStorage->Release();
}
catch (...)
{
// clean up
pStorage->Release();
throw;
}
// return the retrieved application name
return AppName;
// NOTE: You should consider using a smart COM-pointer class
// to eliminate all the exception handling in this code.
}
Good luck,
--
Damon (TeamB)
BCBCAQ--http://bcbcaq.bytamin-c.com
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads