-
September 15th, 2009, 04:33 AM
#1
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.
-
September 15th, 2009, 05:41 AM
#2
Re: Save as with excel automation
Originally Posted by Sami4
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
-
September 15th, 2009, 05:50 AM
#3
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.
-
September 16th, 2009, 11:56 AM
#4
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
Robots are trying to steal my luggage.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|