如何调用excel的API?用VC 6.0…………

我是要写一个程序去查找两个excel文件的表头的内容,如果有相同的,则查找表头下的内容看有没有相同的,再导出相同内容。但我之前没接触过excel的API,谁推荐本书也行…... 我是要写一个程序去查找两个excel文件的表头的内容,如果有相同的,则查找表头下的内容看有没有相同的,再导出相同内容。但我之前没接触过excel的API,谁推荐本书也行………… 展开
 我来答
ziyang64
2011-07-27 · TA获得超过962个赞
知道小有建树答主
回答量:529
采纳率:0%
帮助的人:816万
展开全部
这是我以前写的一段程序,可以参考。 现在没有安装Office,没法试了。
你在百度文库里找“使用MFC操作EXCEL文件”就可以找到资料。
_Application app; // app is an _Application object.
Workbooks books;
LPDISPATCH lpDisp; // Often reused variable.

if(!app.CreateDispatch("Excel.Application"))
{
AfxMessageBox("Couldn't CreateDispatch() for Excel");
return;
}

// Set visible.
app.SetVisible( FALSE );

lpDisp = app.GetWorkbooks(); // Get an IDispatch pointer.
ASSERT(lpDisp);
books.AttachDispatch(lpDisp); // Attach the IDispatch pointer

COleVariant
covTrue((short)TRUE),
covFalse((short)FALSE),
covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);

// To open an existing workbook, you need to provide all
// 13 arguments for the Open member function.
// The code below opens a workbook and adds it to the Workbook's
// Collection object.
// You need to modify the path and file name for your own
// workbook.
//
CString strFile = filename;
lpDisp = books.Open( strFile, // is a workbook.
covOptional, covOptional, covOptional, covOptional, covOptional,
covOptional, covOptional, covOptional, covOptional, covOptional,
covOptional, covOptional ); // Return Workbook's IDispatch pointer.
ASSERT(lpDisp);
book.AttachDispatch( lpDisp );

// Get the Sheets collection and attach the IDispatch pointer to your
// sheets object.
lpDisp = book.GetSheets();
ASSERT(lpDisp);
sheets.AttachDispatch(lpDisp);

long nSheets = sheets.GetCount();

char outfile[256];
for (long no = 1; no <= nSheets; no++)
{
lpDisp = sheets.GetItem( COleVariant((short)( no )) );
ASSERT(lpDisp);
sheet.AttachDispatch(lpDisp);

lpDisp = sheet.GetUsedRange();
ASSERT(lpDisp);
range.AttachDispatch(lpDisp);

/*
Range r = range.GetColumns();
int cc = r.GetCount();
r = range.GetRows();
int rr = r.GetCount();
*/
VARIANT ret = range.GetValue();
if ( ret.vt == VT_EMPTY )
continue;

strcpy(outfile, filename);
char *p = strchr( outfile, '.' );
if ( p )
*p = 0;
CString str = outfile;
str += "_";
str += sheet.GetName();
if ( str.Find( "说明" ) == -1 &&
str.Find( "说明" ) == -1)
{
str_command[ 0 ].Add( str );

int sign = -1;
ftalk->write( (const char*)&sign, 4 );
int n = str_command[ 0 ].GetSize();
ftalk->write( (const char*)&n, 4 );

strcat(outfile, (LPCSTR)sheet.GetName());
strcat(outfile, ".cxx");
//std::ofstream ar(outfile);
std::ofstream ar;
//ar << (LPCSTR)sheet.GetName() << std::endl;

//Create the SAFEARRAY from the VARIANT ret.
COleSafeArray sa(ret);
SaveAsTalk( ar, sa );
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式