|
Can someone direct me to a good tutorial/ description as to how to use Excel in a VC++ app . I need to basically write to an excel file but use the Excel API .
|
|
|
|
|
Obviously, you will need to use OLE to accomplish this. I can't really give you alot of information other than check out MSDN or look on code project for OLE interfaces.
Hopefully that will help. Sorry I can't help more. I haven't done any of this in a while, and I used perl when I did.
Good Luck!
|
|
|
|
|
First you'll need to import from Excel's type library. After that, use the classes that are provided. Here a small snippet that gets two values from the user, plugs them into two cells and puts their sum into a third:
_Application app;
Workbooks books;
_Workbook book;
Worksheets sheets;
_Worksheet sheet;
Range range;
COleVariant vtOptional((long) DISP_E_PARAMNOTFOUND, VT_ERROR),
vtTrue((short) TRUE),
vtFalse((short) FALSE);
CString strText;
if (app.CreateDispatch("Excel.Application") == TRUE)
{
app.SetVisible(TRUE);
books = app.GetWorkbooks();
book = books.Add(vtOptional);
sheets = book.GetSheets();
sheet = sheets.GetItem(COleVariant((short) 1));
range = sheet.GetRange(COleVariant("A1"), COleVariant("A1"));
m_ebCellA1.GetWindowText(strText);
range.SetValue(COleVariant(strText));
range = sheet.GetRange(COleVariant("A2"), COleVariant("A2"));
m_ebCellA2.GetWindowText(strText);
range.SetValue(COleVariant(strText));
range = sheet.GetRange(COleVariant("A4"), COleVariant("A4"));
range.SetFormula(COleVariant("=A1 + A2"));
}
|
|
|
|
|
David - you'll think I'm following you around the newsgroups...but it proves I've searched before asking the question....
Is the Excel API documented. I've got about as far as I can from the tutorials, ie opening a worksheet, updating cells, saving etc. I want to be able to move cells, pivot tables, cut'n'paste, insert formulaes, basically automate Excel from my app.
Cheers
Angel
************************************************************
The sooner you fall behind, the longer you have to catch up.
|
|
|
|
|
Angel1058 wrote:
Is the Excel API documented.
Not to my knowledge. I use trial and error, looking through the .h file, and using VB. Those three together can usually tell me how a particular method works.
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Thanks all for the time taken (again!). I managed to get this far cribbing code from here and there. I am virtually there in what I want to do - it's very basic...
A1 : D4 - a 4x4 grid. I can update any value no problem. When all cells are populated, I need to drop the first column, and move the remaining 3 columns along. The VBA for this is...
Range("B1:D4").Select<br />
Range("B1:D4").Cut Desitination:=Range("A1:C4")<br />
Range("A1:C4").Select
My interpretation (using the API) is
lpDisp = sheet.GetRange(COleVariant("B1") , COleVariant("D4")<br />
range.AttachDispatch(lpDisp);<br />
range.Select();<br />
range.Cut(COleVariant("A1:C4"));
and I get 'Cut method of Range class failed'.
Any chance of you spoon feeding me this last bit please?
Cheers
*********************************************
The sooner you fall behind, the longer you have to catch up.
|
|
|
|
|
Hi,
This has been troublign me fors oem time now.
I have an MFC Application which is Dialog-Based. My 'main' is constructed of initializations and a 'DoModal()' for my dialog, this is AppWizard generated code.
My problem is that my application (or rather dialog window) :
1. fails to respond to the 'Start+M' key-combination (minimize all)
2. when clicking the 'Show Desktop' icon in the quick-launch bar my application disappears, but re-appears when any OTHER application is restored.
3. fails to minimize when clicking it's entry in the task-bar (it dose maximize if it was previously minimized.
I've tried looking at CFrameWnd's implementation for help, but can't find the specifics on this one.
Can someone help ?
Thanks very much
Ohad
|
|
|
|
|
ohadp wrote:
1. fails to respond to the 'Start+M' key-combination (minimize all)
The dialog will need the WS_MINIMIZEBOX style.
|
|
|
|
|
thanks very much.
This solved all my problems. and I thought it was something much more complicated
|
|
|
|
|
Hi,
I have a program that sends messages over the internet. I now need to change it so that i can save the messages to a file. Can someone tell me how to read from a file, open a file, and save to a file?
In my app, all my windows come up from drop down menus. So where should I open the file ?(once I know how) In the main class or the class where all the messages are made?
thanks
Jimmy
Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)
|
|
|
|
|
http://www.codeproject.com/script/comments/forums.asp?msg=593820&forumid=1647#xx593820xx
You'll probably want to create a CStdioFile object if this is going to be a text file. Otherwise, if the messages belong to the document, take advantage of serialization. Most everything is already in place so it's fairly painless.
|
|
|
|
|
Hi,
Can you explain a little more for me? What do you mean that the messages belong to the document? What is serialization?
Did I do something wrong by asking the question yesterday and today? is that why you put the link to my question yesterday? If so, sorry.
Jimmy
Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)
|
|
|
|
|
NewHSKid wrote:
What is serialization?
See this[^] article.
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
NewHSKid wrote:
Did I do something wrong by asking the question yesterday and today? is that why you put the link to my question yesterday? If so, sorry.
No, I was just making you aware that a previous attempt was made to point you in the right direction.
NewHSKid wrote:
Can you explain a little more for me? What do you mean that the messages belong to the document? What is serialization?
I'm guessing that you have either an MDI or an SDI application. If that's the case, it's bound to have a CDocument -derived class. That class will have member variables, which might (it's up to you to decide the most appropriate spot) include the messages you are creating/sending/receiving.
Serialization is well-documented in MSDN (this tool should become part of your arsenal). Here's an excerpt:
“Serialization” is the process of writing or reading an object to or from a persistent storage medium, such as a disk file. MFC supplies built-in support for serialization in the class CObject. Thus, all classes derived from CObject can take advantage of CObject’s serialization protocol.
The basic idea of serialization is that an object should be able to write its current state, usually indicated by the value of its member variables, to persistent storage.
|
|
|
|
|
Thanks for the help....I am reading your tutorial now Ravi.
David, I am sorry, I didn't know where to go with the help i got yesterday. i thought maybe i would get someone to shed some light on how to understand it.
Jimmy
Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)
|
|
|
|
|
The MSDN Scribble example goes a long way in showing the many facets of an MFC application. I suggest you study it in detail.
|
|
|
|
|
Hi people!
I´m starting with GDI+ , so I discovered that I have to lead too much with
the WCHAR type . I´ve got some problems trying to compose a string (using sprintf ) and drawing the resulting text using Graphics::DrawString() (I couldn´t convert a char *string to WCHAR).
Do you know a way to make this convertion , or to compose a WCHAR string just like using sprintf?
Thank you !
|
|
|
|
|
Check out A2W() , MultiByteToWideChar() and related functions.
|
|
|
|
|
Dear All,
I am developing an application in MFC VC++ Version 6.0 for Windows 2000.
I have some contents in a batch file to uninstall my driver.
I need to uninstall the driver without using this batch file, i need to uninstall it from my application only on click of an event. Can any body please tell me API to uninstall the driver using the contents of the batch file
The contents of batch file are:
rundll32.exe setupapi,InstallHinfSection DefaultUninstall 132 .\filespyw2k.inf
I tried using Winexec like
WinExec("rundll32.exe setupapi,InstallHinfSection DefaultUninstall 132 .\filespyw2k.inf",SW_SHOW);
but it showed that installation failed. If i run the batch file it easily uninstalls the driver
Feel free to ask any further queries in this regards,
Thanks
Rohit Dhamija
|
|
|
|
|
It's just a guess but the InstallHinfSection() appears to have the following signature:
void InstallHinfSection( LPCSTR, UINT, LPCSTR );
If that's indeed the case, you could do something like:
hLibrary = Loadlibrary("setupapi.dll");<br />
pFunc = GetProcAddress(hLibrary, "InstallHinfSection");<br />
(*pFunc)("DefaultUninstall", 132, ".\\filespyw2k.inf");<br />
FreeLibrary(hLibrary);
Or you could just call CreateProcess() using the name of the .bat file.
|
|
|
|
|
dear sir,
void InstallHinfSection( LPCSTR, UINT, LPCSTR );
Can you please tell something more about it ?
rohit
|
|
|
|
|
My original hypothesis was wrong. It's a documented function.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/setupapi/setup/installhinfsection.asp
Now you can just link with setupapi.lib and call the function like you do any others.
|
|
|
|
|
Dear David,
I wrote following code, but it is throwing 4 errors
//////////
#include "Setupapi.h"
void main()
{
InstallHinfSection(NULL,NULL,TEXT("DefaultUninstall 132 .\filespyw2k.inf"),0);
}
////////
I am sending the errors also. Can you please help me ??
Thanks in advance
Rohit
The errors are:
--------------------Configuration: p - Win32 Debug--------------------
Compiling...
ss.cpp
c:\program files\microsoft visual studio\vc98\include\setupapi.h(37) : error C2143: syntax error : missing ';' before '*'
c:\program files\microsoft visual studio\vc98\include\setupapi.h(37) : error C2501: 'LPGUID' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\commctrl.h(26) : error C2146: syntax error : missing ';' before identifier 'HRESULT'
c:\program files\microsoft visual studio\vc98\include\commctrl.h(26) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
p.exe - 4 error(s), 0 warning(s)
|
|
|
|
|
Having just #include "Setupapi.h" is not enough for a complete, working program. For a Windows program, you'll need #include <windows.h> , too.
This setupapi.h file assumes the presence of other .h files. For example, line 37 is trying to create a new type (*LPGUID) based on an existing type (GUID). If no other .h files have been included that define GUID, a compiler error is just around the corner.
|
|
|
|
|
I think David means
#include <windows.h>
is required too, before the include of SetupAPI. (I hate it when I forget to tick the "Do not treat <'s as HTML tags" box too!)
<b>S</b><i>teve </i><b>S</b>
|
|
|
|