VC++如何批量将Excel表导入sql2000 本人通过VC++6.0 读取Excel中的数据,然后将其导入sql2000中,现在想通过选择多张Excel表批量导入。请问各位大虾该如何实现?最好能给出具体的例子 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 哈哈,把分给我吧,我刚刚做完这个东西,呵呵,让用户制定要导入数据存放的目录,然后遍历目录,找到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); // 最后结束整个查找工作 } 其他的你如果想要代码,发邮箱吧[email protected] 如果是CSV的话,格式右和数据库一致,可以使用BULK INSERT 问下楼上的,我最近要做一个CSV的导入导出,请问能给我联系方式.指教下我吗? 请问下,CSV是什么意思?我都没有搞得太懂. 这个错误应该怎么改呢? 如何改变mfc对话框程序,edit控件的背景颜色? 菜鸟求教:界面程序"无效索引" 100分求两个函数,ANSI和UTF-8之间的转换 当一个进程在运行的过程中调用另一个进程,那么如何调试另一个进程,这两个进程都是.exe文件 TCP的数据是不是可以被冒认?? UpdateData函数还需要声明吗? 如何向系统发送键盘组合键消息 关于BYTE问题 急 人体运动跟踪,基于视频的,记录手跟关节的一些动作,最好基于opencv的思路 怎样去掉属性页对话框上(比如上一步,下一步)按钮。 求多人聊天室源代码,大送分
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); // 最后结束整个查找工作
}