7 个解决方案
#1
CoGetObject
#2
能说的详细点吗,或者给个例子,谢谢!
#3
通过COM接口连接EXCEL实例,所有事情就可以做了,MSDN中有例子
#4
up
#5
谢谢各位!通过COM,AUTOMATION当然是可以获得,但是我只是要获得文件名包括扩展名,并不对文件进行任何的操作.所以并不想用COM,AUTOMATION.对不起啦,怪我没说清楚!不知不通过这个途径还有没有方法获得?望各位高手不吝赐教!!!
#6
::CoInitialize(NULL);
// Translate server ProgID into a CLSID. ClsidFromProgID
// gets this information from the registry.
CLSID clsid;
CLSIDFromProgID(L"Excel.Application", &clsid);
// Get an interface to the running instance, if any..
IUnknown *pUnk;
HRESULT hr = GetActiveObject(clsid, NULL, (IUnknown**)&pUnk);
ASSERT(!FAILED(hr));
// Get IDispatch interface for Automation...
IDispatch *pDisp;
hr = pUnk->QueryInterface(IID_IDispatch, (void **)&pDisp);
ASSERT(!FAILED(hr));
// Release the no-longer-needed IUnknown...
pUnk->Release();
// ----------------------------------------------------
// Your automation code here-
// ----------------------------------------------------
_Application app;
app.AttachDispatch(pDisp);
_Workbook objBook;
objBook = app.GetActiveWorkbook();
CString name = objBook.GetName();
::CoUnintialize();
// Translate server ProgID into a CLSID. ClsidFromProgID
// gets this information from the registry.
CLSID clsid;
CLSIDFromProgID(L"Excel.Application", &clsid);
// Get an interface to the running instance, if any..
IUnknown *pUnk;
HRESULT hr = GetActiveObject(clsid, NULL, (IUnknown**)&pUnk);
ASSERT(!FAILED(hr));
// Get IDispatch interface for Automation...
IDispatch *pDisp;
hr = pUnk->QueryInterface(IID_IDispatch, (void **)&pDisp);
ASSERT(!FAILED(hr));
// Release the no-longer-needed IUnknown...
pUnk->Release();
// ----------------------------------------------------
// Your automation code here-
// ----------------------------------------------------
_Application app;
app.AttachDispatch(pDisp);
_Workbook objBook;
objBook = app.GetActiveWorkbook();
CString name = objBook.GetName();
::CoUnintialize();
#7
谢谢goodboyws(深夜不眠者(VCMVP)) 的帮助!
但是我是说不想用AUTOMATION,感觉那就是杀鸡用牛刀啊!!!我只是要得到打开文件的名称,不对文件进行操作.
我对AUTOMATION不熟,听别人说如果机器上没装OFFICE,而程序中使用了AUTOMATION的话,程序是运行不了的.
不对的地方大家别笑话!
但是我是说不想用AUTOMATION,感觉那就是杀鸡用牛刀啊!!!我只是要得到打开文件的名称,不对文件进行操作.
我对AUTOMATION不熟,听别人说如果机器上没装OFFICE,而程序中使用了AUTOMATION的话,程序是运行不了的.
不对的地方大家别笑话!
#1
CoGetObject
#2
能说的详细点吗,或者给个例子,谢谢!
#3
通过COM接口连接EXCEL实例,所有事情就可以做了,MSDN中有例子
#4
up
#5
谢谢各位!通过COM,AUTOMATION当然是可以获得,但是我只是要获得文件名包括扩展名,并不对文件进行任何的操作.所以并不想用COM,AUTOMATION.对不起啦,怪我没说清楚!不知不通过这个途径还有没有方法获得?望各位高手不吝赐教!!!
#6
::CoInitialize(NULL);
// Translate server ProgID into a CLSID. ClsidFromProgID
// gets this information from the registry.
CLSID clsid;
CLSIDFromProgID(L"Excel.Application", &clsid);
// Get an interface to the running instance, if any..
IUnknown *pUnk;
HRESULT hr = GetActiveObject(clsid, NULL, (IUnknown**)&pUnk);
ASSERT(!FAILED(hr));
// Get IDispatch interface for Automation...
IDispatch *pDisp;
hr = pUnk->QueryInterface(IID_IDispatch, (void **)&pDisp);
ASSERT(!FAILED(hr));
// Release the no-longer-needed IUnknown...
pUnk->Release();
// ----------------------------------------------------
// Your automation code here-
// ----------------------------------------------------
_Application app;
app.AttachDispatch(pDisp);
_Workbook objBook;
objBook = app.GetActiveWorkbook();
CString name = objBook.GetName();
::CoUnintialize();
// Translate server ProgID into a CLSID. ClsidFromProgID
// gets this information from the registry.
CLSID clsid;
CLSIDFromProgID(L"Excel.Application", &clsid);
// Get an interface to the running instance, if any..
IUnknown *pUnk;
HRESULT hr = GetActiveObject(clsid, NULL, (IUnknown**)&pUnk);
ASSERT(!FAILED(hr));
// Get IDispatch interface for Automation...
IDispatch *pDisp;
hr = pUnk->QueryInterface(IID_IDispatch, (void **)&pDisp);
ASSERT(!FAILED(hr));
// Release the no-longer-needed IUnknown...
pUnk->Release();
// ----------------------------------------------------
// Your automation code here-
// ----------------------------------------------------
_Application app;
app.AttachDispatch(pDisp);
_Workbook objBook;
objBook = app.GetActiveWorkbook();
CString name = objBook.GetName();
::CoUnintialize();
#7
谢谢goodboyws(深夜不眠者(VCMVP)) 的帮助!
但是我是说不想用AUTOMATION,感觉那就是杀鸡用牛刀啊!!!我只是要得到打开文件的名称,不对文件进行操作.
我对AUTOMATION不熟,听别人说如果机器上没装OFFICE,而程序中使用了AUTOMATION的话,程序是运行不了的.
不对的地方大家别笑话!
但是我是说不想用AUTOMATION,感觉那就是杀鸡用牛刀啊!!!我只是要得到打开文件的名称,不对文件进行操作.
我对AUTOMATION不熟,听别人说如果机器上没装OFFICE,而程序中使用了AUTOMATION的话,程序是运行不了的.
不对的地方大家别笑话!