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

几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 (http://www.dimcax.com/hust/index.php)
-   ObjectARX(C++) (http://www.dimcax.com/hust/forumdisplay.php?f=34)
-   -   【转帖】从cad里导出数据到excel档的问题. (http://www.dimcax.com/hust/showthread.php?t=7104)

yang686526 2009-04-16 07:31 PM

【转帖】从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::openexceldb(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;
}


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