基本信息
源码名称:Access大批量数据的导入和导出到Excel
源码大小:1.10M
文件格式:.zip
开发语言:C#
更新时间:2019-05-30
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 4 元 
   源码介绍

上万条数据,毫秒级

导出的excel如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AccessToExcel
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            OleDbConnection con = new OleDbConnection();
            try
            {
                SaveFileDialog saveFile = new SaveFileDialog();
                saveFile.Filter = ("Excel 文件(*.xls)|*.xls");//指定文件后缀名为Excel 文件。
                if (saveFile.ShowDialog() == DialogResult.OK)
                {
                    string filename = saveFile.FileName;
                    if (System.IO.File.Exists(filename))
                    {
                        System.IO.File.Delete(filename);//如果文件存在删除文件。
                    }
                    int index = filename.LastIndexOf("//");//获取最后一个/的索引
                    filename = filename.Substring(index   1);//获取excel名称(新建表的路径相对于SaveFileDialog的路径)
                    //select * into 建立 新的表。
                    //[[Excel 8.0;database= excel名].[sheet名] 如果是新建sheet表不能加$,如果向sheet里插入数据要加$. 
                    //sheet最多存储65535条数据。
                    string sql = "select top 65535 *  into   [Excel 8.0;database="   filename   "].[检测表] from CheckResultTB where 总结果='OK' ";
                    con.ConnectionString="provider=microsoft.ace.oledb.12.0;"   " data source="   Application.StartupPath   "//FaureciaDataBase.accdb"   ";User Id="   ";Persist Security Info=False"   ";Jet OLEDB:Database Password=betterway";
                    //con.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0;Data Source="   Application.StartupPath   "//FaureciaDataBase.mdb";//将数据库放到debug目录下。
                    OleDbCommand com = new OleDbCommand(sql, con);
                    con.Open();
                    com.ExecuteNonQuery();

                    MessageBox.Show("导出数据成功", "导出数据", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                con.Close();
            }
        }
    }
}