見圖。首先必須使用圖中方式創建dll,如果這樣制作dll無法直接讀取Excel,再呼叫其他程式也行
uj5u.com熱心網友回復:
import 方式
// Copyright (C) 1992-1998 Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Visual C++ Language Reference and related
// electronic documentation provided with Microsoft Visual C++.
// See these sources for detailed information regarding the
// Microsoft Visual C++ product.
// NOTE: This example will only work with Excel8 in Office97
// Compile with cl /GX comexcel.cpp
// TO DO: Edit the #import paths
//#pragma message ("Make sure you go to Tools.Options.Directories and add the paths to mso97.dll and vbeext1.olb. Mso97.dll will usually be in c:\\\"Program Files\"\\\"Microsoft Office\"\\Office, and vbeext1.olb will be in c:\\\"Program Files\"\\\"Common Files\"\\\"Microsoft Shared\"\\VBA")
#import "C:\\Program Files\\Common Files\\Microsoft Shared\\Office11\\mso.dll" no_namespace rename("DocumentProperties", "DocumentPropertiesXL")
#import "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\VBA6\\VBE6EXT.OLB" no_namespace
#import "C:\\Program Files\\Microsoft Office\\OFFICE11\\excel.exe" rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL") rename("DocumentProperties", "DocumentPropertiesXL") no_dual_interfaces
#pragma warning (disable:4192)
#include <stdio.h>
#include <tchar.h>
void dump_com_error(_com_error &e)
{
_tprintf(_T("Oops - hit an error!\n"));
_tprintf(_T("\a\tCode = %08lx\n"), e.Error());
_tprintf(_T("\a\tCode meaning = %s\n"), e.ErrorMessage());
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
_tprintf(_T("\a\tSource = %s\n"), (LPCTSTR) bstrSource);
_tprintf(_T("\a\tDescription = %s\n"), (LPCTSTR) bstrDescription);
}
// If this is placed in the scope of the smart pointers, they must be
// explicitly Release(d) before CoUninitialize() is called. If any reference
// count is non-zero, a protection fault will occur.
struct StartOle {
StartOle() { CoInitialize(NULL); }
~StartOle() { CoUninitialize(); }
} _inst_StartOle;
void main()
{
using namespace Excel;
_ApplicationPtr pXL;
try
{
pXL.CreateInstance(L"Excel.Application");
pXL->Visible = VARIANT_TRUE;
WorkbooksPtr pBooks = pXL->Workbooks;
_WorkbookPtr pBook = pBooks->Add();
SheetsPtr pSheets = pBook->Worksheets;
pSheets->Add();
_WorksheetPtr pSheet = pSheets->GetItem("Sheet1");
pSheet->Activate();
pSheet->Range["A1"]->Value2 = 1234L;
Sleep(5000);
pBook->Saved = VARIANT_TRUE;
pXL->Quit();
}
catch(_com_error &e)
{
dump_com_error(e);
pXL->Quit();
}
}
uj5u.com熱心網友回復:
謝謝,如果是讀取csv檔案是否會更簡單uj5u.com熱心網友回復:
CSV就是逗號隔開的一系列值uj5u.com熱心網友回復:
謝謝,這個A1的是不是賦值給1234L?運行的時候檔案必須是打開狀態嗎?讀取的檔案是csv格式,是不是更簡單點?
uj5u.com熱心網友回復:
那又該如何制作非基于mfc的dll呢 ?非常得到你的答復
uj5u.com熱心網友回復:
我這個dll有個輸出函式,要在輸出函式里呼叫csv的值作為引數,如何制作,大神們
uj5u.com熱心網友回復:
用 Excel 填充符合你需求的資料, 另存為 csv, 然后記事本打開慢慢分析轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/120608.html
標籤:基礎類
