|
Sorry that I got your question wrong. I havent worked on office tools, but one of my friend who worked on this told me that he was using excel.h then. I dont know if it might help you or not.
Nikhs
Nikhil Trivedi
|
|
|
|
|
An existing excel document is opened with Open(...) in the Workbooks interface.
Do you have a link to the MSDN example?
Perhaps the explanation becomes more clear if it's based on the example you've based your code on.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
This is the link to the example:
http://support.microsoft.com/kb/308407[^]
As you can see there, the example doesn't open an existing excel file but creates a new (unnamed) one. Second, is uses COleSafeArray in order to access (read/write) an entire range of cells, where I need to access only single cells ...
Thanks for your help ...
|
|
|
|
|
Before you continue you have to be aware that Excel deals with containers.
This means that when you launch Excel with CreateDispatch or similar, the next step is usually to get an interface for the WorkBook collection/container called WorkBooks .
The same goes for the WorkSheet objects in the WorkSheets collection/container and so on.
Once you've got hold of the WorkBooks interface, you call WorkBooks::Open(...) in order to open an existing document, a WorkBook . Then you'll get a WorkBook interface to be able to access the document.
When the WorkBook has been opened, you have to choose which WorkSheet you want to use with WorkBook::get_WorkSheets() and later WorkSheets::get_Item(...) .
For each cell you want to read or write, you have to select a "Range". The example shows this.
Regarding the fact that you don't want to use a SafeArray to write the data, I think you can give a VARIANT as argument to Range::put_Value() with a single value and the type set to e.g. VT_I4 for a 32-bit integer.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
GuyM wrote: My question is how do I open an existing XLS file...
if (app.CreateDispatch("Excel.Application") == TRUE)
{
app.SetVisible(TRUE);
Workbooks books = app.GetWorkbooks();
_Workbook book = books.Open("C:\\Book1.xls",
vtOptional, vtOptional, vtOptional,
vtOptional, vtOptional, vtOptional,
vtOptional, vtOptional, vtOptional,
vtOptional, vtOptional, vtOptional);
...
}
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Great - it worked !! Thanks !!
Now just one more thing ...how do I get/set the value a certain cell (for example A1).
|
|
|
|
|
GuyM wrote: ...how do I set the value a certain cell (for example A1).
Worksheets sheets = book.GetSheets();
_Worksheet sheet = sheets.GetItem(COleVariant((short) 1));
Range range = sheet.GetRange(COleVariant("A1"), COleVariant("A1"));
range.SetValue(COleVariant("12345.6"));
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
HI i want to set a particular cell to RED color ??
and also while quittin the application, the excel file need to be saved....
|
|
|
|
|
hellogany wrote: HI i want to set a particular cell to RED color ??
Range range = sheet.GetRange(COleVariant("A1"), COleVariant("A1"));
Interior interior = range.GetInterior();
interior.SetColorIndex(COleVariant(3L)); hellogany wrote: and also while quittin the application, the excel file need to be saved....
So you might want to call Save() or SaveAs() .
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
thanks for the reply.
i have to find a value in the excel cell and should replace a new value in that cell
Can u help me on this issue?
gany
|
|
|
|
|
hellogany wrote: i have to find a value in the excel cell...
Look at the Range::Find() method.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
DavidCrow wrote: Range range = sheet.GetRange(COleVariant("A1"), COleVariant("A1"));Interior interior = range.GetInterior();interior.SetColorIndex(COleVariant(3L));
I've been looking all over for how to change the color - thanks to you it works - but just a simple question- Why is 3L = red? How does this color index thing work? Is there a way to use RGB with the 3 params to get any color?
Thank you again!
Mike
|
|
|
|
|
thready wrote: Why is 3L = red?
Because that's what the designer of that type library decided.
thready wrote: How does this color index thing work?
I'm not sure what you are asking here. Just use the OLE/COM Object Viewer to find out the other values.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
just make a dialog with mfc-wizard.
add message function like this
void CTest::OnLButtonDown(UINT nFlags, CPoint point)
{
PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x,point.y));
CDialog::OnLButtonDown(nFlags, point);
}
and exacute it.
1) click the client area of dialog with left mouse button.
2) move it toward screen top
3)when the some part of dialog is in off-screen, release mouse left button.
4)automatically the dialog is moved again to screen area. <= it is my problem.
normal window acts like this.
how can I disable 4) action?
I want to prevent the dialog from automatically moving back onto screen.
thank you in advance.
<hello world="">
|
|
|
|
|
david_joung wrote: automatically the dialog is moved again to screen area.
Use DM_REPOSITION message to move dialog back onto screen.
|
|
|
|
|
david_joung wrote: 4)automatically the dialog is moved again to screen area. <= it is my problem.
So what exactly are you wanting to happen?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I want to prevent the dialog from automatically moving back onto screen.
<hello world="">
|
|
|
|
|
david_joung wrote: I want to prevent the dialog from automatically moving back onto screen.
Are either of these plausible?
1) Don't process the WM_LBUTTONDOWN message, or 2) Don't post the WM_NCLBUTTONDOWN message
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
sir,
I am working on vc++ 7.0 project and it is based on MDI Compound document view architecture and I am trying to embed an active-x component into my project.
why it takes more time, when i try to create a component on the display document for the first time. The same component when i try to create subsequent time it takes less time. could you please throw some light on it.
Is there any efficient way to write code by which we reduce time while creation of Active-x component.
Below is the code which creates the component
CView* pActiveView = pInterfaceObject->GetActiveView();//getting the handle of active view
if (pActiveView)
{
COleServerDoc* pActiveDocument = (COleServerDoc*)pActiveView->GetDocument(); //assigning the handle to the COleServerDoc.
ASSERT_KINDOF(COleServerDoc, pActiveDocument);
m_pClientItem = new COleClientItem (pActiveDocument,this);//creating a container
}
m_pClientItem->CreateNewItem((REFCLSID)(clsid)); //creating the Active X control through known classid
ASSERT_VALID(m_pClientItem);
if(m_pClientItem)
{
IDualChart *pDualChart;
if (FAILED(m_pClientItem->m_lpObject->QueryInterface(__uuidof(pDualChart), (void**)&pDualChart)))
{
AfxMessageBox(_T("Query interace failed"));
return bStatus;
}
m_pChart.Attach(pDualChart);
Thanks & Regards,
Praveen A.
praveena@navayuga.co.in
pv_pravin@yahoo.co.in
|
|
|
|
|
I would like to know about how to desgin Architecture of Network security project.
Arvind kumar sharma
software Developer
|
|
|
|
|
Hi,
I have a character array and want that to be assigned to cstring object, how can i do that.
I have tried the assignment operator, but it is copying upto end line character, and leaving the other character.
Does any one know about that?
Warm Regards,
Mushq
|
|
|
|
|
Look at the constructor of the CString class,
CString( const unsigned char* psz );<br />
throw( CMemoryException );
Regards,
Paresh.
|
|
|
|
|
<br />
<br />
#include<string.h><br />
char str[30];<br />
std::string temp;<br />
CString val;<br />
<br />
strcpy(str,"Hello");<br />
temp=str;<br />
val.Empty();<br />
<br />
val=temp.c_str();<br />
<br />
Viral Joshi.
|
|
|
|
|
|
So you have a NULL inside your array. If it were possible what you want to do, CString wouldn't be a string class; A string should terminate with NULL symbol ('\0') to make itself be a string.
--
=====
Arman
|
|
|
|