SOL9 Sample: DocToTxtApplet

SOL9 Samples

1 Screenshot


2 Source code

/*
 * DocToTxtApplet.cpp 
 * Copyright (c) 2009 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */



// This is a sample program to convert a WordDoc file  to a Text file.

#include <sol/office/WordApplet.h>
#include <sol/office/WordDocument.h>

#include <sol/BString.h>


void _tmain(int argc, TCHAR** argv)
{
    if (argc !=2) {
        printf("Usage: DocToTxtApplet.exe DocFullPathName\n");
        return;
    }

    try {
        BString docname = argv[1];
        WordApplet applet;

        try {
            WordDocument document = applet.open((BSTR)docname, false);
            printf("Opend a document %S\n", (BSTR)docname);

            BString txtFile = docname + ".txt";
            _variant_t newfilename = (BSTR)txtFile;
            _variant_t format = (short)Word::wdFormatText;

            document.saveAs(&newfilename, &format);
            printf("Saved As %S\n", (BSTR)txtFile);

            document.close();
            printf("Closed a document\n");

        } catch (HRESULT hr) {
            printf("Exception %x\n", hr);
        } catch (...) {
            printf("Unknown Exception \n");
        }

    } catch (HRESULT hr) {
        printf("Exception %x\n", hr);
    } catch (...) {
        printf("Unknown Exception \n");
    }
}


Last modified: 9 Apr 2010

Copyright (c) 2010 Antillia.com ALL RIGHTS RESERVED.