几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » AutoCAD二次开发 » ObjectARX(C++)
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


回复
 
主题工具 搜索本主题 显示模式
旧 2009-04-16, 07:31 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】从cad里导出数据到excel档的问题.

从cad里导出数据到excel档的问题.
从cad里导出数据到excel档的问题.
各位我现在把cad数据导入到excel档案后为了方便,程式没有自动关掉excel,如果采用手动关掉excel,电脑进程里面的excel.exe无法关掉,如果执行几次就会产生几个excel.exe进程,请高手指教一下.假如要在程式里面关掉excel请问用什么函数.
可否回复一下呀
你把excel当作一个数据库来做就可以了
给你一段函数看看,该函数是将clistctrl控件的数据保存到excel中
//使用odbc将数据输出到excel数据区
void cglobalfuns::exportasexcel(clistctrl &listctrl)
{
cstring sdriver = "microsoft excel driver (*.xls)"; // excel安装驱动
cstring sexcelfile;
//弹出对话框选择路径
cfiledialog filedlg(false,null,"baseerr.xls",ofn_filemustexist| ofn_hidereadonly,"(*.xls)|*.xls|");
if( filedlg.domodal() == idok)
{
sexcelfile = filedlg.getpathname(); // 要建立的excel文件
cfilefind finder;
bool bworking = finder.findfile(sexcelfile);//寻找文件
if (bworking)//如果已经存在文件,则删除
{
cfile::remove((lpctstr)sexcelfile);
}
}
else return;
try
{
_connectionptr pconnection;
cstring sql;
// 创建进行存取的字符串
sql.format("driver={%s};dsn='';firstrowhasnames=1;readonly=false;create_db=\"%s\";dbq=%s",sdriver, sexcelfile, sexcelfile);
if(!cdboperation:penexceldb(pconnection,sql))
{
afxmessagebox("保存失败!");
return;
}
cheaderctrl* pheader = listctrl.getheaderctrl();
//获得行,列的个数
int ncolcount = pheader->getitemcount();
int nlinecount = listctrl.getitemcount();
int colorderarray[100];
cstring ca[100];
listctrl.getcolumnorderarray(colorderarray, ncolcount);
//检索各列的信息,确定列标题的内容
for(int i =0 ; i< ncolcount; i++)
{
lvcolumn lvc;
char text[100];
lvc.mask = lvcf_text|lvcf_subitem;
lvc.psztext = text;
lvc.cchtextmax = 100;
listctrl.getcolumn(colorderarray[i], &lvc);
ca[i] = lvc.psztext;
}
// 创建表结构
cstring tempsql="(";
for(i = 0 ; i < ncolcount-1; i++)
{
tempsql += "[";
tempsql += ca[i];
tempsql += "]";
tempsql += " text,";
}
tempsql += "[";
tempsql += ca[ncolcount-1];
tempsql += "]";
tempsql += " text)";
sql = "create table sheet1 ";
sql += tempsql;
if(!cdboperation::executesql(pconnection,sql))
{
afxmessagebox("创建表结构失败!");
return;
}
//插入数据
int item_count=listctrl.getitemcount();
tempsql="(";
for(i =0 ; i< ncolcount-1; i++)
{
tempsql += "[";
tempsql+=ca[i];
tempsql += "]";
tempsql+=" ,";
}
tempsql += "[";
tempsql+=ca[ncolcount-1];
tempsql += "]";
tempsql+=")";
for(int itemnum = 0;itemnum < item_count;itemnum++)
{
sql = "insert into sheet1 ";
sql += tempsql;
sql += "values ('";
for(i =0 ; i< ncolcount-1; i++)
{
sql += listctrl.getitemtext(itemnum, i);
sql += "','";
}
sql += listctrl.getitemtext(itemnum, ncolcount-1);
sql += "')";
if(!cdboperation::executesql(pconnection,sql))
{
afxmessagebox("保存数据失败!");
return;
}
}
// 关闭数据库
pconnection->close();
afxmessagebox("excel文件写入成功!");
}
catch_all(e)
{
trace1("excel驱动没有安装: %s",sdriver);
}
end_catch_all;
}
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭



所有的时间均为北京时间。 现在的时间是 09:38 PM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多