本人通过VC++6.0 读取Excel中的数据,然后将其导入sql2000中,现在想通过选择多张Excel表批量导入。请问各位大虾该如何实现?最好能给出具体的例子

解决方案 »

  1.   

    哈哈,把分给我吧,我刚刚做完这个东西,呵呵,让用户制定要导入数据存放的目录,然后遍历目录,找到xls后缀的文件,剩下的就是读excel表,写入Sql了,呵呵
    CString dirPath;
    ChooseDirectory(dirPath);
    /*$功能:弹出对话框选择要导入的目录
       传入参数:文件路径(path)$*/
    void CTransExcelView::ChooseDirectory(CString & path)
    {
    char   buffer[MAX_PATH];   
    BROWSEINFO   m_pbi;   
        
    ::ZeroMemory(&m_pbi,sizeof(BROWSEINFO)); 

    m_pbi.hwndOwner = GetSafeHwnd();   
    m_pbi.pszDisplayName = buffer;   
    m_pbi.lpszTitle = "选择要导入的目录!";   
    m_pbi.ulFlags =BIF_RETURNONLYFSDIRS;   
        
    ITEMIDLIST   *idl  = ::SHBrowseForFolder(&m_pbi);   
    if (idl)   
    {   
    ::SHGetPathFromIDList(idl,buffer);   

    path =buffer;
    }
    int i = _chdir(dirPath); //进入要查找的路径(也可为某一具体的目录)  Search_Directory(szFilename); //要查找的文件名称void CTransExcelView::Search_Directory(char *selFileName)
    {
    CTransExcelDoc * pDoc = GetDocument(); long handle; 
    struct _finddata_t filestruct;
    //表示文件(或目录)的信息
    char path_search[_MAX_PATH]; 

    //表示查找到的路径结果
    // 开始查找工作, 找到当前目录下的第一个实体(文件或子目录), 
    //*表示查找任何的文件或子目录, filestruct为查找结果 

    handle = _findfirst("*", &filestruct); 

    // 如果handle为-1, 表示当前目录为空, 则结束查找而返回 
    if(-1==handle)
    return;
    // 检查找到的第一个实体是否是一个目录(filestruct.name为其名称) 
    // CString temp = filestruct.name;
    // int len = temp.GetLength();
    if(::GetFileAttributes(filestruct.name) & FILE_ATTRIBUTE_DIRECTORY) 

    // 如果是目录, 则进入该目录并递归调用函数Search_Dirctory进行查找, 
    // 注意: 如果目录名的首字符为.(即为.或..), 则不用进行查找 
    if( filestruct.name[0] != '.') 

    _chdir(filestruct.name); 

    Search_Directory(selFileName); 
    // 查找完毕之后, 返回上一级目录 
    _chdir(".."); 


    else // 如果第一个实体不是目录, 则检查是否是要查找的文件 
    {
    CString temp = filestruct.name;
    // stricmp对两字符串进行小写形式的对比, 返回为0表示完全一致 
    // if(!stricmp(filestruct.name, selFileName)) 
    int findresult = temp.Find(selFileName);
    if(-1!=findresult)

    // 先获得当前工作目录的全路径
    _getcwd(path_search,_MAX_PATH); 
    //再获得文件的完整的路径名(包含文件的名称) 
    strcat(path_search,"\\"); 
    strcat(path_search,filestruct.name);

    // MessageBox(path_search); //输出显示
    pDoc->ReadExcel(path_search);

    pDoc->WriteToSQL();
    }


    // 继续对当前目录中的下一个子目录或文件进行与上面同样的查找 
    while(!(_findnext(handle,&filestruct))) 

    if( ::GetFileAttributes(filestruct.name) & FILE_ATTRIBUTE_DIRECTORY) 
    {
    if(*filestruct.name != '.') 

    _chdir(filestruct.name); 
    Search_Directory(selFileName); 
    _chdir(".."); 


    else 

    CString temp = filestruct.name;
    // if(!stricmp(filestruct.name, selFileName)) 
    int findresult = temp.Find(selFileName);
    if(-1!=findresult)

    _getcwd(path_search,_MAX_PATH); 
    strcat(path_search,"\\"); 
    strcat(path_search,filestruct.name);

    // MessageBox(path_search); 
    pDoc->ReadExcel(path_search);
    pDoc->WriteToSQL();




    _findclose(handle); // 最后结束整个查找工作 

    }
      

  2.   

    其他的你如果想要代码,发邮箱吧[email protected]
      

  3.   

    如果是CSV的话,格式右和数据库一致,可以使用BULK INSERT
      

  4.   

    问下楼上的,我最近要做一个CSV的导入导出,请问能给我联系方式.指教下我吗?
      

  5.   

    请问下,CSV是什么意思?我都没有搞得太懂.