使用到的知识点
在Windows操作系统中读和写excel;
关闭指定名字的exe进程,打开指定名字的exe进程;
使生成的exe在windows各个系统中兼容;
源码下载链接
http://pan.baidu.com/share/home?uk=369664793&view=share#category/type=0
说明
读取excel数据采用的是微软的office COM类库。核心源码在excel.cpp文件中,核心函数为HRESULT AutoWrap(int autoType, VARIANT *pvResult, IDispatch *pDisp, LPOLESTR ptName, int cArgs...);对外接口是CString** GetExcelData(string &fileAddress);输入为excel文件路径名,输出为一个二维数组,对应excel文件中的每个格点的字符串数据。
写入excel文件采用的是基于COM库实现的basicexcel,参考链接为:http://blog.csdn.net/augusdi/article/details/13295735。
运行IcMatchTool.exe关闭之后,在任务管理器中观察该进程没有关闭,没有去深究原因,直接采用一个新的进程关闭该进程。
关闭指定名字的exe进程,参考链接:http://blog.csdn.net/caroline_wendy/article/details/29382347
软件截图
软件说明
1.IcLibrary.xls和input.xls都需要在最后一行手动加一个end;
2.IcLibrary为元器件库文件,input为需匹配的元器件文件;
3.点击“匹配”按钮之后,在弹出的文件选择框中选择input.xls即可;
4.文件中的close.exe不能删除。
5.yes.xls是在元器件库中找到的元器件,no.xls是在元器件中没有找到的元器件;
6.如果需匹配的元器件文件input.xls较大,程序需要运行较长时间,等待有“匹配完成”的弹窗出来即可。
核心源码
void CEXCELACESSDlg::OnMath() { //打开库文件 string LibraryFileAddress("D:\IcManage\icLibrary.xls"); CString **getLibData = GetExcelData(LibraryFileAddress); //row_num multimap<string,int> libMap; int libRowNum = row_num; for(int i = 1;i<libRowNum;i++) { string tmp(getLibData[i][0].GetBuffer()); libMap.insert(pair<string,int>(tmp,i)); getLibData[i][0].ReleaseBuffer(); } //打开需要匹配的文件 _TCHAR strFileFilter[] = "excel 文件(*.xlsx;*.xls)|*.xlsx;*.xls|文本文件(*.txt)|*.txt|所有文件(*.*)|*.*||"; CFileDialog Dlg(TRUE,NULL ,NULL, OFN_HIDEREADONLY,strFileFilter); //修改默认打开路径 Dlg.m_ofn.lpstrInitialDir=_T("D:\IcManage"); if(Dlg.DoModal()==IDOK) { m_FILE=Dlg.GetFileName(); PathName=Dlg.GetPathName(); UpdateData(FALSE); } string mathFileAddress(PathName.GetBuffer()); CString **getMathData = GetExcelData(mathFileAddress); PathName.ReleaseBuffer(); int mathRowNum = row_num; //创建输出的Yes.xls和No.xls文件 BasicExcel eYes,eNo; BasicExcelWorksheet *sheetYes,*sheetNo; char bufYes[200],bufNo[200]; CString yesName,noName; string yesAddress("D:\IcManage\yes.xls"); string noAddress("D:\IcManage\no.xls"); yesName.Format("%s", yesAddress.c_str()); noName.Format("%s", noAddress.c_str()); int k; for(k=0;k<yesName.GetLength();k++) bufYes[k]=yesName.GetAt(k); bufYes[k]=0; for(k=0;k<noName.GetLength();k++) bufNo[k]=noName.GetAt(k); bufNo[k]=0; eYes.Load(bufYes); eNo.Load(bufNo); eYes.New(1); eNo.New(1); r1 = 0; r2 = 0; sheetYes = eYes.GetWorksheet("Sheet1"); sheetNo = eNo.GetWorksheet("Sheet1"); string tmp_yes,tmp_no; for(int j = 0;j<3;j++) { string s(getLibData[0][j].GetBuffer()); if(j==2) tmp_yes.append("总"); tmp_yes.append(s); tmp_yes.append(" "); tmp_no.append(s); tmp_no.append(" "); } tmp_no.append("