libopc
opc_type.c

Demonstrate how to corretly get the type of an Office document.

/*
Corretly get the type and an Office document.
Ussage:
opc_type FILENAME
Sample:
opc_type OOXMLI1.docx
*/
#include <opc/opc.h>
#ifdef WIN32
#include <crtdbg.h>
#endif
int main( int argc, const char* argv[] )
{
#ifdef WIN32
_CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
for(int i=1;i<argc;i++) {
opcContainer *c=opcContainerOpen(_X(argv[1]), OPC_OPEN_READ_ONLY, NULL, NULL);
opcRelation rel=opcRelationFind(c, OPC_PART_INVALID, NULL, _X("http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"));
if (OPC_PART_INVALID!=mainPart) {
const xmlChar *type=opcPartGetType(c, mainPart);
printf("Office Document Type: %s\n", type);
if (0==xmlStrcmp(type, _X("application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"))) {
printf("WORD Document\n");
} else if (0==xmlStrcmp(type, _X("application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml"))) {
printf("POWERPOINT Document\n");
} else if (0==xmlStrcmp(type, _X("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"))) {
printf("EXCEL Document\n");
}
}
}
}
#ifdef WIN32
OPC_ASSERT(!_CrtDumpMemoryLeaks());
#endif
return 0;
}