使用ADO,调用Excel 2000的文件内容,可以读写以及删除操作!!!!高分在线等待!!!!

Lanber 2003-01-15 01:46:26
我想使用Excel 2000的文件,在VC中,通过ADO来操作,最好有实例!


急急急急急急急急急急急急急急急急急急急急急急急急!!@#!@#!@

...全文
223 3 打赏 收藏 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
arvid_gs 2003-01-15
  • 打赏
  • 举报
回复
try
{
_Application app; // app is an _Application object.
_Workbook book; // More object declarations.
_Worksheet sheet;
Workbooks books;
Worksheets sheets;

Range range; // Used for Microsoft Excel 97 components.
LPDISPATCH lpDisp; // Often reused variable.

// Common OLE variants. Easy variants to use for calling arguments.
COleVariant
covTrue((short)TRUE),
covFalse((short)FALSE),
covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);

// Start Microsoft Excel, get _Application object,
// and attach to app object.
if(!app.CreateDispatch("Excel.Application"))
{
AfxMessageBox("Couldn't CreateDispatch() for Excel");
return;
}


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

// Register the Analysis ToolPak.
CString sAppPath;

sAppPath.Format ("%s\\Analysis\\Analys32.xll", app.GetLibraryPath());

if(!app.RegisterXLL(sAppPath))
AfxMessageBox("Didn't register the Analys32.xll");

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

// Open a new workbook and attach that IDispatch pointer to the
// Workbook object.
lpDisp = books.Add( covOptional );
ASSERT(lpDisp);
book.AttachDispatch( lpDisp );

// To open an existing workbook, you need to provide all
// arguments for the Open member function. In the case of
// Excel 2002 you need to provide 16 arguments.
// The code below opens a workbook and adds it to the Workbook's
// Collection object. It shows 13 arguments, required for Excel
// 2000.
// You need to modify the path and file name for your own
// workbook.

//
// lpDisp = books.Open("C:\\Test", // Test.xls is a workbook.
// covOptional, covOptional, covOptional, covOptional, covOptional,
// covOptional, covOptional, covOptional, covOptional, covOptional,
// covOptional, covOptional ); // Return Workbook's IDispatch
// pointer.

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

// Get sheet #1 and attach the IDispatch pointer to your sheet
// object.
lpDisp = sheets.GetItem( COleVariant((short)(1)) );
//GetItem(const VARIANT &index)
ASSERT(lpDisp);
sheet.AttachDispatch(lpDisp);

// Fill range A1 with "1/25/98", the settlement date.
lpDisp = sheet.GetRange(COleVariant("A1"), COleVariant("A1"));
ASSERT(lpDisp);
range.AttachDispatch(lpDisp);
range.SetValue(COleVariant("1/25/98")); // Excel 97 & Excel 2000

range.SetValue2(COleVariant("1/25/98")); // Excel 2002


// Fill range A2 with "11/15/99", the maturity date.
lpDisp = sheet.GetRange(COleVariant("A2"), COleVariant("A2"));
ASSERT(lpDisp);
range.AttachDispatch(lpDisp);
range.SetValue(COleVariant("11/15/99")); // Excel 97 & Excel 2000

range.SetValue2(COleVariant("11/15/99")); // Excel 2002


// Fill range A3 with "2", the frequency for semi-annual interest
// payments.
lpDisp = sheet.GetRange(COleVariant("A3"), COleVariant("A3"));
ASSERT(lpDisp);
range.AttachDispatch(lpDisp);
range.SetValue(COleVariant("2")); // Excel 97 & Excel 2000

range.SetValue2(COleVariant("2")); // Excel 2002

// Fill range A4 with 1, the basis (actual/actual).
lpDisp = sheet.GetRange(COleVariant("A4"), COleVariant("A4"));
ASSERT(lpDisp);
range.AttachDispatch(lpDisp);
range.SetValue(COleVariant("1")); // Excel 97 & Excel 2000

range.SetValue2(COleVariant("1")); // Excel 2002

// Fill range C1 with the formula "=COUPNCD(A1, A2, A3, A4)" and
// format the cell with a Date type of the Number format.
lpDisp = sheet.GetRange(COleVariant("C1"), COleVariant("C1"));
ASSERT(lpDisp);
range.AttachDispatch(lpDisp);
range.SetNumberFormat(COleVariant("mm/dd/yy"));
range.SetFormula(COleVariant("=COUPNCD(A1, A2, A3, A4)"));

/* This is an alternative that works without placing variables on
// the worksheet.
// The values are arguments contained in the SetFormula() call.
// range.SetFormula(COleVariant(
"=COUPNCD(\"09/15/96\",\"11/15/99\",2,1)"));
*/

// *** The example in this block uses a built-in Microsoft Excel
// function.

// You do not have to register any add-in to use the built-in

// Microsoft Excel worksheet functions.
lpDisp = sheet.GetRange(COleVariant("C3"), COleVariant("C3"));
ASSERT(lpDisp);
range.AttachDispatch(lpDisp);
range.SetFormula(COleVariant("=SUM(A3, A4)"));
// or use:
// range.SetFormula(COleVariant("=SUM(2,1)"));

// *** End of example for built-in function usage.

// Release dispatch pointers.
range.ReleaseDispatch();
sheet.ReleaseDispatch();
// This is not really necessary because
// the default second parameter of AttachDispatch releases
// when the current scope is lost.

} // End of processing.

catch(COleException *e)
{
char buf[1024]; // For the Try...Catch error message.
sprintf(buf, "COleException. SCODE: %08lx.", (long)e->m_sc);
::MessageBox(NULL, buf, "COleException", MB_SETFOREGROUND | MB_OK);
}

catch(COleDispatchException *e)
{
char buf[1024]; // For the Try...Catch error message.
sprintf(buf,
"COleDispatchException. SCODE: %08lx, Description: \"%s\".",
(long)e->m_wCode,(LPSTR)e->m_strDescription.GetBuffer(512));
::MessageBox(NULL, buf, "COleDispatchException",
MB_SETFOREGROUND | MB_OK);
}

catch(...)
{
::MessageBox(NULL, "General Exception caught.", "Catch-All",
MB_SETFOREGROUND | MB_OK);
}
okin 2003-01-15
  • 打赏
  • 举报
回复
看MS网站上的例子比较好
http://support.microsoft.com/default.aspx?scid=kb;en-us;q178781
sunyou 2003-01-15
  • 打赏
  • 举报
回复
这个是ODBC方式:
http://www.vckbase.com/document/viewdoc.asp?id=421

用友有个控件也可以读写Excel文件。
名称:Excel读写控件
版本:1.2
大小:2.8M
主页:http://www.cellsoft.cc
下载地址:http://61.135.139.207/china/chanpin/xiazai/download.htm
效果演示:
http://61.135.139.207/china/chanpin/jiazu/excelShow/ConvertExcel.htm
源码链接: https://pan.quark.cn/s/a4b39357ea24 微信小程序是由腾讯公司设计的一种轻量级应用开发平台,主要面向移动设备,旨在为用户带来无需下载安装即可直接使用的应用服务体验。在微信小程序的开发实践中,"模仿美团菜单 swiper分类菜单"是一项常见的技术应用,其目的是达成与美团外卖应用相似的交互模式,使用户能够轻松地浏览和挑选各种商品或服务。 在微信小程序的技术体系中,`swiper`组件属于轮播图功能模块,通常用于呈现多张图片或卡片式的切换界面,能够达成动态滑动展示不同分类菜单的功能。在模拟美团菜单的应用情境下,`swiper`组件一般与`swiper-item`组件协同工作,每一个`swiper-item`对应一个分类,用户可通过左右滑动来切换不同的分类菜单。 为了达成这样的功能,首先需要在微信小程序的`json`配置文档中引入`swiper`组件,并在`wxml`结构文档中构建相应的布局代码,将每个分类以`swiper-item`的形式进行组织。同时,需要在`wxss`样式文档中定义恰当的样式,保证分类菜单的视觉呈现符合设计规范。 接下来,我们将在`js`逻辑文档中处理`swiper`的切换逻辑,通过监听`bindchange`事件来识别当前选中的分类,并根据这一信息动态获取对应的子菜单信息。为了达成类似美团的层级菜单功能,可能还需要借助`picker`或`navigator`组件来展示二级分类或商品详情。 在开发阶段,需要关注以下关键点: 1. 数据绑定:保证数据与界面之间的双向链接准确无误,以便在选择分类时即时更新显示内容。 2. 动态加载:针对大量数据,可能需要采取异步加载机制,防止一次性加载过多内容引发性能瓶颈...
代码下载地址: https://pan.quark.cn/s/72bd50ecb2fb 《微信飞机大战素材详解》 微信飞机大战作为一款广受欢迎的休闲游戏,凭借其便捷的操作方式和紧张刺激的游戏过程,赢得了众多用户的青睐。本文将系统性地剖析这款游戏的关键素材,旨在帮助开发者全面掌握游戏的设计理念与实现方法。 我们聚焦于游戏的核心构成——"AirplaneResource"。此名称一般指向游戏资源库,其中收纳了游戏中所有的视觉素材、音频资料以及动画元素。在微信飞机大战的语境下,这些资源构成了游戏画面呈现、音效播放和动态效果的基础。 1. **图像素材**:游戏中的飞机造型、敌方单位、弹药以及爆炸效果等视觉元素,均以图像素材的形式进行展示。图像素材通常涵盖PNG或JPG格式的静态图片,也包括GIF或APNG格式的动态图片。开发者需要细致地设计并优化这些图像,确保在各种设备上都能实现流畅的渲染,同时维持视觉表现力。 2. **声音素材**:游戏的背景音乐、射击音效、爆炸声等音频片段,对于构建游戏氛围具有决定性作用。这些音频文件可能以MP3、WAV或OGG格式进行存储,开发者需要权衡音频的压缩程度与音质,以确保在不牺牲游戏体验的前提下,有效控制文件体积。 3. **动画序列**:飞机的飞行轨迹、攻击动作、爆炸过程等动态表现,通常借助序列帧动画技术实现。这些序列帧图片组合而成的动画,通过编程控制播放速率和顺序,为游戏增添生动的动态效果。 4. **物理接触判定**:游戏中飞机与弹药之间的接触判定,是通过算法完成的。开发者可能会采用基础的矩形接触判定或更精密的像素级接触判定,以保证游戏的公平性和挑战性。 5. **游戏规则**:微信飞机大战的得分机制、生命值系统、敌机生成逻辑等...

4,017

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧