我写了一段读取并判断Excel文件内容的代码,如图,为什么连Excel都打不开啊

解决方案 »

  1.   

    从//判断、循环 之前是可以运行,可以打开Excel文件的
      

  2.   

    void CExcelTestDlg::OnBnClickedButton3()
    {
    // TODO: 在此添加控件通知处理程序代码

    //获取文件路径
    CFileDialog* lpszOpenFile;
    CString szGetName;
    lpszOpenFile = new CFileDialog(TRUE,"","",OFN_FILEMUSTEXIST|OFN_HIDEREADONLY,"Excel File(*.xlsx;*.xls)|*.xls;*.xlsx",NULL);

    if (lpszOpenFile->DoModal()==IDOK)
    {
    szGetName = lpszOpenFile->GetPathName();
    SetWindowText(szGetName); delete lpszOpenFile;
    }
    else
    return;

    //打开文件
    //文件中包含多个sheet时,默认打开第一个sheet
    CExport2Excel Excel_example;
    Excel_example.OpenExcel(szGetName);
    //获取已使用表格行列数
    int iRows = Excel_example.GetRowCount();
    int iCols = Excel_example.GetColCount(); //读Excel中的数据
    for(int row=2 ; row<=iRows; row++)
    {for (int r =2;r<=iRows; r++)
    {CString h=Excel_example.GetText (r,7); //CString型转化为int型
    int m=_ttoi(h); //判断、循环
    if (m>=5)
    {CString str;
     str.Format("%f,a");
         GetDlgItem(IDC_EDIT_2)->SetWindowText(str);
    }
    else return ;
    }
    }
    }
      

  3.   

    不用这么复杂 http://blog.csdn.net/sunnyloves/article/details/9996669
      

  4.   

    CExport2Excel 这个类没用过
      

  5.   

    是不是因为那个 delete 引起的?你把它删了试试