|
use Excel automation
CApplication app;
CRange range;
CWorkbook book;
CWorkbooks books;
CWorksheet sheet;
CWorksheets sheets;
VARIANT ret;
COleVariant covTrue((short)TRUE),covFalse((short)FALSE),covOptional((long)DISP_E_PARAMNOTFOUND,VT_ERROR);
try
{
CoInitialize(NULL);
if(!app.CreateDispatch("Excel.Application"))
{
AfxMessageBox("Cannot start Excel");
return;
}
books = app.get_Workbooks();
book = books.Open(fname,covOptional,covOptional,covOptional,covOptional
,covOptional,covOptional,covOptional,covOptional
,covOptional,covOptional,covOptional,covOptional
,covOptional,covOptional); // different for different ver of Excel
// check msdn website
sheets = book.get_Worksheets();
sheet = sheets.get_Item(COleVariant((short)1));
sprintf(cell,"%c%d",alpha[k],j); // eg A1, A2, etc
range = sheet.get_Range(COleVariant(cell),COleVariant(cell));
ret = range.get_Value2();
CString t = ret.bstrVal; // t will hold the value of the cell
books.Close();
app.Quit(); // close excel application remember to close application
}
catch(COleException *e)
{
char buf[1024];
sprintf(buf, "COleException %081x.", (long)e->m_sc);
}
catch(COleDispatchException *e)
{
char buf[1024];
sprintf(buf, "COleDispatchException %081x.", (long)e->m_wCode);
}
catch(...)
{
char buf[1024];
sprintf(buf, "General Exception");
}
hope tis helps
Thomas
|
|
|
|
|
I use Visual Studio 6. Is it possible to select a rectangular area that does not start from column zero, and copy that text?
|
|
|
|
|
Are you refering to Visual studio editor???
|
|
|
|
|
i think he means into the source editor ; the behavior is the one we could find into UltraEdit under the feature called "Column mode selection".
but i don't know how to do this in VS6...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
In the source editor you can press Alt key and select using the mouse.
|
|
|
|
|
excelent...
thanks, and thank you also for Mr Flace (who is the poster of the original question)...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Awesome! this is what I was looking for. Thanks.
|
|
|
|
|
But one thing, while pasting the recangle block you have to give necessary blank lines, else will be appended to the exiting lines....
|
|
|
|
|
actually, in some cases that is desirable too!
|
|
|
|
|
True..
|
|
|
|
|
I have a project that I need to communicate with another host PC using MODBUS/ TCP. I have no idea in doing this MODBUS TCP program. Can give some source code in doing this MODBUS TCP. I really need help.
THANKS for help.
|
|
|
|
|
|
i created a DLL with some functions that i'd use in a VB or someother application,
but the problem is for every exported function , i need to do like
[code]
Private Declare Function MyTestFun1 Lib "MDLL.dll" (ByVal hWnd As Long, ByVal a As Integer, b As Integer) As Integer
Private Declare Function MyTestFun2 Lib "MDLL.dll" (ByVal hWnd As Long, ByVal a As Integer, b As Integer) As Integer
[/code]
what i need is like, when u create an object using Microsoft scripting runtime, you'll get access to FileSystemObject. (fso)
so in VB, you do like
[code]
Dim fso as new fileSystemObject
later on you'd use all functions by fso.(dot)..
[/code]
how'd i do my own dll like MSScripting runtime..?
regards,
Rookie
-- modified at 4:37 Thursday 22nd September, 2005
|
|
|
|
|
Try creating DLL through ATL COM and make each function as interface.
<bold>- Nilesh
<italics>"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|
|
There are two things you need to do:
First define your functions in the DLL so VB can call them correctly:
// DLL external entry points for VB
long WINAPI MyTestFun1(HWND hwnd, int a, int b)
long WINAPI MyTestFun2(HWND hwnd, int a, int b)
// Then you will need a def file for the DLL so the entries are public and VB can pull them out
LIBRARY MDLL
DESCRIPTION 'Test DLL'
EXETYPE WINDOWS
EXPORTS
MyTestFun1 @1
MyTestFun2 @2
Your VB defines look correct so it should work with these changes.
|
|
|
|
|
Good day,
I want to create a CListBox in which item index 0 & 1 have image(bmp or icon) with text and the next indexes are plain text. How can i achieve it?
I have search examples and found an image listbox but when i insert plain text on the successing index, still the plain text will not be on its normal location that is on the leftmost area because the area now is reserve for image, but i only wanted index 0 and index 1 to have an image, the rest is plain text.
Thanks a lot.
More Power!
|
|
|
|
|
What styles does the listbox have?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
LBS_NOTIFY | WS_VSCROLL | WS_BORDER
Selection:Single,
Owner Draw:Fixed,
Has String enabled,
Thanks...
|
|
|
|
|
By the way im on Embedded Visual C++, in case it matters
|
|
|
|
|
Anonymous wrote:
Owner Draw:Fixed,
Just a guess, but what happens if you use LBS_OWNERDRAWVARIABLE instead of LBS_OWNERDRAWFIXED ?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Ok I'll try.
Thanks David.
|
|
|
|
|
I want the information about
how can we implement the camera capture click event in MFC application in VC++.
|
|
|
|
|
Could you explain that?
Don't try it, just do it!
|
|
|
|
|
Hi, currently, I have an activeX control which will be created by one thread, and control will be used by many other thread. I only wish ONE thread to access the same method at ONE time.
What If
1. My control already have a synchronized mechanism handling, i.e. each method of the control is protected by CRITICAL_SECTION. May I know which thread model i should use?
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED) - single thread
or
CoInitializeEx(NULL, CO_MULTITHREADED) - multi thread
2. My control method is not protected by any CRITICAL_SECTION. again, what thread model i should use?
thanks!
cheok
|
|
|
|
|
If you don't have a sycronization mechanism in your control use COINIT_APARTMENTTHREADED (single threaded apartment) but make sure you call CoInitialize in each thread you want to access the control, and also you have to marshall object's interfaces to all threads from which you want to call the control, otherwise you'll get an exception.
If you have a syncronization mechanism use the other model, multi threaded apartment and in this case you don't have to marshall interfaces.
|
|
|
|