Save as with excel automation
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Save as with excel automation

  1. #1
    Join Date
    Jul 2005
    Posts
    8

    Save as with excel automation

    Hello all.

    I need your help because i want to save an excel sheet (i have 2 sheet) to an txt file (File Type : Text (DOS) ).
    To do that, i use the following article from microsoft "How to automate Excel from C++ without using MFC or #import" (http://support.microsoft.com/kb/216686/en).
    Here a piece of my code:

    if( file == NULL) {
    MessageBox(NULL, "Nom du fichier manquant", "Error", 0x10010);
    return false;
    }

    WCHAR str[MAX_PATH];
    MultiByteToWideChar(CP_ACP, 0,file, -1, str, MAX_PATH);

    VARIANT vaPath;
    vaPath.vt = VT_BSTR;
    vaPath.bstrVal = SysAllocString(str);

    AutoWrap(DISPATCH_METHOD, NULL, xlBook.pdispVal, L"SaveAs", 1, vaPath);

    SysFreeString(vaPath.bstrVal);
    VariantClear(&vaPath);

    SetSave(true);
    }

    I found any informations doc in this forum anf if you could help me.
    Thanks by advance for your help.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,011

    Re: Save as with excel automation

    Quote Originally Posted by Sami4 View Post
    Hello all.

    I need your help because i want to save an excel sheet (i have 2 sheet) to an txt file (File Type : Text (DOS) ).
    To do that, i use the following article from microsoft "How to automate Excel from C++ without using MFC or #import" (http://support.microsoft.com/kb/216686/en).
    Here a piece of my code: ...
    So, what is the problem?
    Victor Nijegorodov

  3. #3
    Join Date
    Jul 2005
    Posts
    8

    Re: Save as with excel automation

    Thanks VictorN.


    To understand, when you save a sheet manually, you have a dialog box and you choose the name and the type of the file :

    File Name :example.fdf
    File Type : Text (DOS)

    In my case, i don't want to save it like 'classeur Microsoft Excel but to an Text (DOS) when using autowrap example.
    Thanks.

  4. #4
    Join Date
    Apr 2002
    Location
    Michigan, USA
    Posts
    860

    Re: Save as with excel automation

    The way I have AutoWrap set up in my program I have to use the arguments in reverse order.

    See
    http://www.codeguru.com/forum/showth...ighlight=excel

    Code:
    VARIANT result;
    VariantInit(&result);
    VARIANT fname;
    fname.vt = VT_BSTR;
    fname.bstrVal=::SysAllocString(L"C:\\output.txt");
    VARIANT fformat;
    fformat.vt = VT_I4;
    fformat.lVal=20;
    AutoWrap(DISPATCH_METHOD, &result, pXlSheet, L"SaveAs", 2,fformat, fname);
    Last edited by Tom Frohman; September 16th, 2009 at 12:00 PM.
    Verere testudinem! (Fear the turtle)

    Once you can accept the universe as matter expanding into nothing that is something, wearing stripes with plaid comes easy. -Albert Einstein

    Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. -Cicero

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center