mysql 表 导入指定的excel  sheet1$里

解决方案 »

  1.   

    1、导成TXT文件,在EXCEL中导入;
    2、用第三方控件导;
    3、用JETSQL导出EXCEL。
      

  2.   

    to wwwwb:
    我是程序里的导出、导入功能。。不能掉第三方文件。
    mysql自带导出excel,把表名当做了sheet$,不知道这个怎么做的~
      

  3.   

    select * into outfile "c:\sheet1$.xls" from tbname;
      

  4.   

    赞楼上的。
    再来个直接了当的。mysql> SELECT * FROM pathway INTO OUTFILE 'd:/pathway.csv' FIELDS ESCAPED BY '\"\"' TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\r\n';
    Query OK, 3 rows affected (0.01 sec)mysql>
    详见:
    http://code.anjanesh.net/2007/12/export-mysql-data-to-excel-compatible.html
    此文介绍的蛮精彩的。
      

  5.   

    to vipper23:
    你们可能误会我意思了(access)
    insert into [Excel 8.0;Database=E:\\text.xls].[订单$] select * from table
    我是像要个这样的效果
    以前我是用access做数据库的,一句话了事。。现在mysql好像不好实现啊~
    订单是excel里的一个sheet
    以前的订单(sheet)已经包含了标题。(可以忽略这个);
      

  6.   

    呵呵 ,我说的JETSQL就是这个意思:
    try:
    SELECT * INTO [Excel 8.0;Database=E:\\text.xls].[订单] 
    from tt IN ODBC[ODBC;Driver={MySQL ODBC 5.1 driver};Server=localhost;Port=3306;Database=tmp;USER=root;Pwd=123;]
      

  7.   

    SELECT * INTO [Excel 8.0;Database=E:\\text.xls].[订单]  
    from [ODBC;Driver={MySQL ODBC 5.1 driver};Server=localhost;Port=3306;Database=tmp;USER=root;Pwd=123;].tt用ADO连接一个MDB OR XLS文件,具有 相应权限
      

  8.   

    那不等于把Excel也当DB操作了?那样起来要增加很多代码。。麻烦一些
      

  9.   

    只是导入到EXCEL中,代码很多吗?
      

  10.   

    SELECT * INTO [Excel 8.0;Database=E:\\text.xls].[订单]   
    from tt;
    我在navicat内操作的,根本不认。。[]改''都不认;执行不了我不能用ado去打开一个excel连接,那样改动太大了。
      

  11.   

    我的意思是我的程序代码,创建excel连接conn  and recordset
    只想通过改动sql语句达到我的目的。
    要不代码和底层的一些dll都要改动了
      

  12.   

    那是JETSQL的命令,不是MYSQL的,当然要出错如果不想变动程序,那就用上述SELECT INTO OUTFILE方法吧
      

  13.   

    SELECT * INTO [Excel 8.0;Database=E:\\text.xls].[订单]  from tt; 不推荐这种方法,反而把问题复杂化,一个简单的功能反而要依赖于三个不同的部件。建议使用  #3楼 vipper23( 的方法。
      

  14.   

    ACCESS 结构
    姓名   年龄
    张     22
    excel 已经存在标题结构,然后导入
    效果如下:
    姓名   编号   代码
    张         mysql
    姓名   年龄
    张     22
    outfile的话,直接完蛋,完全覆盖。。
    access
    姓名   年龄
    张     22
    郁闷中
    晕死了,换个表这么麻烦~~~
    wwwb,你的语句我试了,我已经打开了mysql连接,没调用后边的链接字符,
    mysql
    SELECT * INTO [Excel 8.0;Database=E:\\text.xls].[订单] from table;
    返回失败。改数据库几天了,就是今天卡到这里了。
    access语句:
    insert into [Excel 8.0;Database=E:\\text.xls].[订单$] select * from table
    差别不大啊。。,wwwwwb,你那个可以成功么?
      

  15.   

    SELECT * INTO [Excel 8.0;Database=E:\\text.xls].[订单]   
    from [ODBC;Driver={MySQL ODBC 5.1 driver};Server=localhost;Port=3306;Database=tmp;USER=root;Pwd=123;].tt早就测试成功了,注意,是JETSQL,非MYSQL的SQL。
    SELECT INTO OUTFILE是要生成新文件的
      

  16.   

    调试不过。你们用什么语言?wo yong c++数据库没问题
    我就是把连接的那段语句放开,也是不行
    简单的其他sql语句,可以成功;_ConnectionPtr pConn(__uuidof(Connection));
    _RecordsetPtr pRst(__uuidof(Recordset));
    pConn->ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0; \
    Data Source=E:\\food86\\src\\bin\\fd.f86; \
    Jet OLEDB:Database Password=food86";
    try
    {
    pConn->Open("","","",adConnectUnspecified);
    CString strSource;
    strSource.Format("insert into [Excel 8.0;Database=%s].[%s$] select * from %s",
    //[ODBC;Driver={MySQL ODBC 5.1 driver};\
    //Server=localhost;Port=3306;Database=trm_base;USER=root;Pwd=food86;option=16386;].%s",
    "E:\\test.xls","订单", "query_book_user");
    pRst->Open(_variant_t(strSource),
    _variant_t(pConn,true),
    adOpenDynamic,
    adLockOptimistic,
    adCmdText);
    }
    catch (_com_error& err)
    {
    CString s;
    s.Format("%s",err.Description());
    AfxMessageBox(s);
    }
    pRst->Close();
    pConn->Close();
    pRst.Release();
      

  17.   

    pConn->ConnectionString="DRIVER={MySQL ODBC 5.1 Driver}; \
    //  server=localhost; \
    //   database=trm_base;uid=root;pwd=food86;option=16386;";
    是这段,发错了。。~
      

  18.   

    1、ODBC配置好,有相应权限
    2、
    在ACCESS中运行
    SELECT * INTO [Excel 8.0;Database=E:\\text.xls].[订单]   
    from [ODBC;Driver={MySQL ODBC 5.1 driver};Server=localhost;Port=3306;Database=tmp;USER=root;Pwd=123;].tt
    3、将SQL语句显示出来;
    4、最好重新发贴。
      

  19.   

    1、ODBC配置没问题的。
    2、第一次发成access了,是在mysql运行的
    [订单] [订单$],这2个我都试了,都不行
    3、sql语句显示出来也不行
    调试代码如下:
    _ConnectionPtr pConn(__uuidof(Connection));
    _RecordsetPtr pRst(__uuidof(Recordset));

    //mysql
    pConn->ConnectionString="DRIVER={MySQL ODBC 5.1 Driver}; \
       server=localhost; \
       database=trm_base;uid=root;pwd=food86;option=16386;";

    try
    {
    pConn->Open("","","",adConnectUnspecified);
    CString strSource;
    strSource.Format("insert into [Excel 8.0;Database=%s].[%s] select * from \
    [ODBC;Driver={MySQL ODBC 5.1 driver};\
    Server=localhost;Port=3306;Database=trm_base;USER=root;Pwd=food86;option=16386;].%s",
    "E:\\test.xls","订单", "query_book_user");
    pRst->Open(_variant_t(strSource),
    _variant_t(pConn,true),
    adOpenDynamic,
    adLockOptimistic,
    adCmdText);
    }
    catch (_com_error& err)
    {
    CString s;
    s.Format("%s",err.Description());
    }
    pRst->Close();
    pConn->Close();
    pRst.Release();pRs->Close()时报错,说明pRst->Open失败,没有打开。
    换成select * from query_book_user这样的语句没问题
      

  20.   

    你 仔细看看的回答,

    用ADO连接一个MDB OR XLS文件
    注意,是JETSQL,非MYSQL的SQL

    你的ADO连接在哪里,发新贴
      

  21.   

    pConn是连接,先定义了pConn->ConnectionString
    pConn->Open("","","",adConnectUnspecified);pRst执行语句,_Recordset
    pRst->Open(_variant_t(strSource),
    _variant_t(pConn,true),
    adOpenDynamic,
    adLockOptimistic,
    adCmdText);
      

  22.   

    pConn->ConnectionString="DRIVER={MySQL ODBC 5.1 Driver}; \
    server=localhost; \
    database=trm_base;uid=root;pwd=food86;option=16386;";
    连接是的MYSQL,非MDB OR XLS文件
    注意,是JETSQL,非MYSQL的SQL
      

  23.   

    o,你的意思是连接excel文件,把mysql作为导入的数据源,导入到excel里?
      

  24.   

    pConn->ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;\
    Data Source=E:\\test.xls;\
    Extended Properties=Excel 8.0;\
    Persist Security Info=False"; try
    {
    pConn->Open("","","",adConnectUnspecified);
    CString strSource;
    strSource.Format("insert into [%s] select * from \
    [ODBC;Driver={MySQL ODBC 5.1 driver};\
    Server=localhost;Port=3306;Database=trm_base;USER=root;Pwd=food86;option=16386;].%s",
    "E:\\test.xls","订单", "query_book_user");
    pRst->Open(_variant_t(strSource),
    _variant_t(pConn,true),
    adOpenDynamic,
    adLockOptimistic,
    adCmdText);
    }
    catch (_com_error& err)
    {
    CString s;
    s.Format("%s",err.Description());
    }
    pRst->Close();
    pConn->Close();
    pRst.Release();
      

  25.   

    pConn->ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;\
    Data Source=E:\\test.xls;\
    Extended Properties=Excel 8.0;\
    Persist Security Info=False"; try
    {
    pConn->Open("","","",adConnectUnspecified); _RecordsetPtr adorstTemp = pConn->OpenSchema(adSchemaTables);
    CString m_strSheet = (LPCTSTR)(_bstr_t)(adorstTemp->GetFields()->GetItem("TABLE_NAME")->Value);
    CString strSource;
    strSource.Format("insert into [Excel 8.0;Database=%s].[%s] select * from \
    [ODBC;Driver={MySQL ODBC 5.1 driver};\
    Server=localhost;Port=3306;Database=trm_base;USER=root;Pwd=food86;option=16386;].%s",
    "E:\\test.xls","订单", "query_book_user");
    pRst->Open(_variant_t(strSource),
    _variant_t(pConn,true),
    adOpenDynamic,
    adLockOptimistic,
    adCmdText);
    }
    catch (_com_error& err)
    {
    CString s;
    s.Format("%s",err.Description());
    }
    pRst->Close();
    pConn->Close();
    pRst.Release();
      

  26.   

    _com_error error = DB_E_NOTABLE
      

  27.   

    strSource内容显示出来看看

    insert into [Excel 8.0;Database=E:\\text.xls].[订单$]   
    select * from [ODBC;Driver={MySQL ODBC 5.1 driver};Server=localhost;Port=3306;Database=tmp;USER=root;Pwd=123;].tt
      

  28.   

    SQL语句是什么?什么原因报错?
      

  29.   

     (1)select * into ***************
    (2) insert into ************
    当时我用access的时候,导出excel,用的是第2个
    现在excel作为ado连接,导入excel,用的是第一个。
    第二个不行。当时没留意你的
      

  30.   

    第一句(select into from)要求目标表(destTbl)不存在,因为在插入时会自动创建。
    第二句(insert into select from)要求目标表(destTbl)存在,由于目标表已经存在,所以我们除了插入源表(srcTbl)的字段外,还可以插入常量我通过excel的字段,和mysql匹配,生成了个临时表,然后直接把临时表创建到excel了,重新生成的excel文件,自己改、删sheet,以前access时,直接导入带标题的excel的,已经存在的表。2个都是微软的,他们可以自己匹配到字段,原理上导出到一个已经生成的表里,是个旧表
    mysql---excel就不行,所以原理上是生成了一个新表