Excel和数据库数据互相转换

说明

支持Mysql和SQL Server的表内的数据转换成Excel,也可以把Excel的数据导入到二者数据库中,Oracle没有测试过。

开发环境Visual Studio2010

开发语言C#

注意

在VS中使用Mysql,需要在VS中引用一个Mysql.Data.dll文件,具体请自行搜索

代码

sqlBase.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;

namespace Excel2Database
{
    class sqlBase
    {
        #region 数据库的连接
        static SqlConnection conn;
        //static MySqlConnection 
        static string database;
        static string user;
        static string password;
        static string IPaddress;
        
        public static bool sqlConnect(string IPaddress1,string database1,string user1,string password1)
        {
            IPaddress = IPaddress1;
            database = database1;
            user = user1;
            password = password1;
            string str = "Data Source=" + IPaddress + ";Initial Catalog =" + database + "; User ID=" + user + "; Password=" + password + "; Connection Timeout=3";
            conn = new SqlConnection(str);
            try
            {
                conn.Open();
            }
            catch
            {
                return false;
            }
            return true;
        }
        #endregion

        public static void sqlDisconnect()
        {
            if (conn.State == ConnectionState.Open)
                conn.Close();
        }

        #region 读取出数据库内所有的表名称
        public static void SetTableNames()
        {
            DataTable tablenames;
            OleDbConnection cn = new OleDbConnection();
            cn.ConnectionString = "Provider=SQLOLEDB;Data Source=" + IPaddress + ";User ID=" + user + ";Password=" + password + ";Initial Catalog=" + database;
            try
            {
                cn.Open();
                tablenames = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new Object[] { null, null, null, "TABLE" });
                Form1.GetTableNames(tablenames);
            }
            catch (SqlException ex)
            {
                throw new Exception(ex.ToString());
            }            
        }
        #endregion

        #region 将DataTable中的数据导入数据库
        public static void CreateNewTable(string tableName,DataTable dt)
        {
            string sqlPhrase = "CREATE TABLE " + tableName + "(";
            foreach (DataColumn dc in dt.Columns)
            {
                //sqlPhrase = sqlPhrase + dc.ColumnName + " CHAR(" + Convert.ToString(dc.ColumnName.ToString().Length + 3) + "),";        
                sqlPhrase = sqlPhrase + dc.ColumnName + " TEXT,";
            }
            sqlPhrase = sqlPhrase.Substring(0, sqlPhrase.Length - 1);
            sqlPhrase = sqlPhrase + ")";
            ExeSQL(sqlPhrase);
            foreach (DataRow dr in dt.Rows)
            {
                sqlPhrase = "insert into " + tableName + " values(";
                foreach (object ob in dr.ItemArray)
                {
                    sqlPhrase = sqlPhrase + "'"+ob.ToString() + "',";
                }
                sqlPhrase = sqlPhrase.Substring(0, sqlPhrase.Length - 1);
                sqlPhrase += ")";
                ExeSQL(sqlPhrase);
            }

        }
        #endregion

        #region 执行SQL语句并返回一个表
        public static DataTable ExeSQLdt(string sql)
        {
            try
            {
                SqlDataAdapter da = new SqlDataAdapter(sql, conn);
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
            catch (SqlException ex)
            {
                throw new Exception(ex.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
        #endregion

        #region  执行SQL语句
        public static int ExeSQL(string sql)
        {
            if (conn.State != ConnectionState.Open)
                conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);
            try
            {
                cmd.ExecuteNonQuery();
                return 0;
            }
            catch (SqlException ex)
            {
                throw new Exception(ex.ToString());
            }
            finally
            {
                cmd.Dispose();
                conn.Close();
            }
        }
        #endregion
    }
}

mysqlBase.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;
using MySql.Data.MySqlClient;

namespace Excel2Database
{
    class mysqlBase
    {
        static MySqlConnection conn;
        static string database ;
        static string user ;
        static string password ;
        static string IPaddress;

        public static bool sqlConnect(string IPaddress1,string database1, string user1, string password1)
        {
            IPaddress = IPaddress1;
            database = database1;
            user = user1;
            password = password1;
            string str = "Server=" + IPaddress + ";Database=" + database + ";Uid=" + user + ";Pwd=" + password + ";";
            conn = new MySqlConnection(str);
            try
            {
                conn.Open();
            }
            catch
            {
                return false;
            }
            return true;
        }

        public static void sqlDisconnect()
        {
            if (conn.State == ConnectionState.Open)
                conn.Close();
        }

        public static void SetTableNames()
        {
            string str = "select table_name from information_schema.tables where table_schema='"+database+"' and table_type='base table';";
            Form1.GetTableNames(ExeSQLdt(str));
        }

        public static void CreateNewTable(string tableName, DataTable dt)
        {
            string sqlPhrase = "CREATE TABLE " + tableName + "(";
            foreach (DataColumn dc in dt.Columns)
            {    
                sqlPhrase = sqlPhrase + dc.ColumnName + " TEXT,";
            }
            sqlPhrase = sqlPhrase.Substring(0, sqlPhrase.Length - 1);
            sqlPhrase = sqlPhrase + ")";
            ExeSQL(sqlPhrase);
            foreach (DataRow dr in dt.Rows)
            {
                sqlPhrase = "insert into " + tableName + " values(";
                foreach (object ob in dr.ItemArray)
                {
                    sqlPhrase = sqlPhrase + "'" + ob.ToString() + "',";
                }
                sqlPhrase = sqlPhrase.Substring(0, sqlPhrase.Length - 1);
                sqlPhrase += ")";
                ExeSQL(sqlPhrase);
            }

        }

        public static DataTable ExeSQLdt(string sql)
        {
            try
            {
                MySqlDataAdapter da = new MySqlDataAdapter(sql, conn);
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
            catch (MySqlException ex)
            {
                throw new Exception(ex.ToString());
            }
            finally
            {
                conn.Close();
            }
        }

        public static int ExeSQL(string sql)
        {
            if (conn.State != ConnectionState.Open)
                conn.Open();
            MySqlCommand cmd = new MySqlCommand(sql, conn);
            try
            {
                cmd.ExecuteNonQuery();
                return 0;
            }
            catch (MySqlException ex)
            {
                throw new Exception(ex.ToString());
            }
            finally
            {
                cmd.Dispose();
                conn.Close();
            }
        }


    }
}

oracleBase.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OracleClient;

namespace Excel2Database
{
    class oracleBase
    {
        static OracleConnection conn;
        static string database ;
        static string user ;
        static string password ;
        static string IPaddress;

        public static bool sqlConnect(string IPaddress1,string database1, string user1, string password1)
        {
            IPaddress = IPaddress1;
            database = database1;
            user = user1;
            password = password1;
            string str = "Server=127.0.0.1;Database=" + database + ";Uid=" + user + ";Pwd=" + password + ";";
            conn = new OracleConnection(str);
            try
            {
                conn.Open();
            }
            catch
            {
                return false;
            }
            return true;
        }

        public static void sqlDisconnect()
        {
            if (conn.State == ConnectionState.Open)
                conn.Close();
        }

        public static void SetTableNames()
        {
            string str = "select table_name from information_schema.tables where table_schema='" + database + "' and table_type='base table';";
            Form1.GetTableNames(ExeSQLdt(str));
        }

        public static void CreateNewTable(string tableName, DataTable dt)
        {
            string sqlPhrase = "CREATE TABLE " + tableName + "(";
            foreach (DataColumn dc in dt.Columns)
            {
                sqlPhrase = sqlPhrase + dc.ColumnName + " TEXT,";
            }
            sqlPhrase = sqlPhrase.Substring(0, sqlPhrase.Length - 1);
            sqlPhrase = sqlPhrase + ")";
            ExeSQL(sqlPhrase);
            foreach (DataRow dr in dt.Rows)
            {
                sqlPhrase = "insert into " + tableName + " values(";
                foreach (object ob in dr.ItemArray)
                {
                    sqlPhrase = sqlPhrase + "'" + ob.ToString() + "',";
                }
                sqlPhrase = sqlPhrase.Substring(0, sqlPhrase.Length - 1);
                sqlPhrase += ")";
                ExeSQL(sqlPhrase);
            }

        }

        public static DataTable ExeSQLdt(string sql)
        {
            try
            {
                OracleDataAdapter da = new OracleDataAdapter(sql, conn);
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
            catch (OracleException ex)
            {
                throw new Exception(ex.ToString());
            }
            finally
            {
                conn.Close();
            }
        }

        public static int ExeSQL(string sql)
        {
            if (conn.State != ConnectionState.Open)
                conn.Open();
            OracleCommand cmd = new OracleCommand(sql, conn);
            try
            {
                cmd.ExecuteNonQuery();
                return 0;
            }
            catch (OracleException ex)
            {
                throw new Exception(ex.ToString());
            }
            finally
            {
                cmd.Dispose();
                conn.Close();
            }
        }

    }
}

Form1.cs

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.Windows.Forms;
using System.IO;
using System.Reflection;

namespace Excel2Database
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            comboBox_sqls.SelectedIndex = 0;
            groupBox2.Enabled = false;
            groupBox3.Enabled = false;
        }

        private delegate void GETTABLENAMES(DataTable dt);
        private static int choice = 0;//0为空,1为Mysql,2为SQLServer,3为Oracle

        public static void GetTableNames(DataTable dt)
        {
            if (comboBox_tables.InvokeRequired)
            {
                GETTABLENAMES gtn = new GETTABLENAMES(GetTableNames);
                comboBox_tables.Invoke(gtn, new object[] { dt });
            }
            else
            {
                comboBox_tables.Items.Add("---- 请选择 ----");
                foreach (DataRow dr in dt.Rows)
                {
                    comboBox_tables.Items.Add((string)dr["TABLE_NAME"]);
                }
                comboBox_tables.SelectedIndex = 0;
                groupBox2.Enabled = true;
                groupBox3.Enabled = true;
            }
        }

        private void DatabaseToExcel(string FileName, DataTable dt)
        {
            Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
            xlApp.Visible = true;
            if (xlApp == null)
            {
                MessageBox.Show("创建Excel文件失败!");
                return;
            }
            Microsoft.Office.Interop.Excel.Workbook xlBook=xlApp.Workbooks.Add(Missing.Value);
            int col = 0, row = 2;
            foreach (DataColumn dc in dt.Columns)
            {
                xlApp.Cells[1, col + 1] = dc.ColumnName.ToString();
                col++;
            }
            foreach (DataRow dr in dt.Rows)
            {
                col = 0;
                foreach (object ob in dr.ItemArray)
                {
                    xlApp.Cells[row, col + 1] = ob.ToString();
                    col++;
                }
                row++;
            }
            xlBook.SaveAs(FileName, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
            xlBook = null;
            xlApp.Quit();
            xlApp = null;
            MessageBox.Show("导出成功");
        }

        private void ExcelToDatabase(string excelFile,string tableName)
        {
            FileInfo fi = new FileInfo(excelFile);
            string strCon="";
            if (fi.Extension == "xls")
                strCon = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + excelFile + ";" + "Extended Properties='Excel 8.0;HDR=NO;IMEX=1';";
            else
                strCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excelFile + ";Extended Properties=\"Excel 12.0;HDR=YES\"";
            OleDbConnection xlsCon = new OleDbConnection(strCon);
            DataTable dt = new DataTable();
            string sqlPhrase="SELECT * FROM [Sheet1$]";
            OleDbDataAdapter da = new OleDbDataAdapter(sqlPhrase, xlsCon);
            try
            {
                da.Fill(dt);
            }
            catch (System.Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            if (choice == 1)
                mysqlBase.CreateNewTable(tableName, dt);
            else if(choice==2)
                sqlBase.CreateNewTable(tableName, dt);
            else if(choice==3)
                oracleBase.CreateNewTable(tableName, dt);
            MessageBox.Show("导入成功");
        }

        private void button_connect_Click(object sender, EventArgs e)
        {
            if (comboBox_sqls.SelectedIndex != 1 && comboBox_sqls.SelectedIndex != 2 && comboBox_sqls.SelectedIndex!=3)
            {
                MessageBox.Show("请选择数据库类型");
                return;
            }
            if (textBox_IP.Text.Trim()=="" || textBox_database.Text.Trim() == "" || textBox_user.Text.Trim() == "" || textBox_password.Text.Trim() == "")
            {
                MessageBox.Show("请将登录信息填写完整");
                return;
            }
            choice = comboBox_sqls.SelectedIndex;
            this.Cursor = Cursors.WaitCursor;
            if (choice == 1)
            {
                if (!mysqlBase.sqlConnect(textBox_IP.Text,textBox_database.Text, textBox_user.Text, textBox_password.Text))
                    MessageBox.Show("数据库连接失败!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                else
                {
                    //MessageBox.Show("success");
                    mysqlBase.SetTableNames();
                }
            }
            else if(choice==2)
            {
                if (!sqlBase.sqlConnect(textBox_IP.Text,textBox_database.Text, textBox_user.Text, textBox_password.Text))
                    MessageBox.Show("数据库连接失败!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                else
                {
                    //MessageBox.Show("success");
                    sqlBase.SetTableNames();
                }
            }
            else if (choice == 3)
            {
                if (!oracleBase.sqlConnect(textBox_IP.Text,textBox_database.Text, textBox_user.Text, textBox_password.Text))
                    MessageBox.Show("数据库连接失败!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                else
                {
                    //MessageBox.Show("success");
                    oracleBase.SetTableNames();
                }
            }
            this.Cursor = Cursors.Arrow;
        }

        private void button_disconnect_Click(object sender, EventArgs e)
        {
            if (choice == 1)
                mysqlBase.sqlDisconnect();
            else if (choice == 2)
                sqlBase.sqlDisconnect();
            else if (choice == 3)
                oracleBase.sqlDisconnect();
            comboBox_tables.Items.Clear();
            groupBox2.Enabled = false;
            groupBox3.Enabled = false;
            choice = 0;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog ChooseExcelSavePath = new FolderBrowserDialog();
            if (ChooseExcelSavePath.ShowDialog() == DialogResult.OK)
                textBox_path.Text = ChooseExcelSavePath.SelectedPath.ToString();
        }

        private void button_Excel_Click(object sender, EventArgs e)
        {
            if (comboBox_tables.SelectedIndex==0)
            {
                MessageBox.Show("请选择需要导出的一张表");
                return;
            }
            if (textBox_path.Text.ToString().Trim() == "")
            {
                MessageBox.Show("请输入路径!");
                return;
            }
            DirectoryInfo di = new DirectoryInfo(textBox_path.Text);
            if (!di.Exists)
            {
                MessageBox.Show("请输入正确的路径!");
                return;
            }
            if (textBox_ExcelName.Text.ToString().Trim() == "")
            {
                MessageBox.Show("请输入文件名!");
                return;
            }
            this.Cursor = Cursors.WaitCursor;
            string excelFileName = textBox_path.Text + "\\" + textBox_ExcelName.Text + ".xlsx";
            if(choice==1)
                DatabaseToExcel(excelFileName, mysqlBase.ExeSQLdt("select * from " + comboBox_tables.SelectedItem.ToString()));
            else if(choice==2)
                DatabaseToExcel(excelFileName, sqlBase.ExeSQLdt("select * from " + comboBox_tables.SelectedItem.ToString()));
            else if (choice == 3)
                DatabaseToExcel(excelFileName, oracleBase.ExeSQLdt("select * from " + comboBox_tables.SelectedItem.ToString()));
            this.Cursor = Cursors.Arrow;
            //MessageBox.Show("导出成功");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (ChooseExcelFile.ShowDialog() == DialogResult.OK)
                textBox_excel.Text = ChooseExcelFile.FileName;
        }

        private void comboBox_tables_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox_tables.SelectedIndex != 0)
                textBox_ExcelName.Text = comboBox_tables.SelectedItem.ToString() ;
            else
                textBox_ExcelName.Text = "";
        }

        private void button_Database_Click(object sender, EventArgs e)
        {
            FileInfo fi = new FileInfo(textBox_excel.Text);
            if (!fi.Exists)
            {
                MessageBox.Show("请选择Excel文件!");
                return;
            }
            string tableName = textBox_TableName.Text.Trim();
            if (tableName.Trim().Length == 0)
            {
                MessageBox.Show("请输入数据表名称");
                return;
            }
            bool isExist=false;
            foreach (object ob in comboBox_tables.Items)
            {
                if (ob.ToString() == tableName)
                {
                    isExist = true;
                    break;
                }
            }
            if (isExist)
            {
                MessageBox.Show("该表名已存在,请更换");
                return;
            }
            this.Cursor = Cursors.WaitCursor;
            ExcelToDatabase(textBox_excel.Text, tableName);
            this.Cursor = Cursors.Arrow;
        }        
    }
}

Form1.Designer.cs

namespace Excel2Database
{
    partial class Form1
    {
        /// <summary>
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows 窗体设计器生成的代码

        /// <summary>
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.button_disconnect = new System.Windows.Forms.Button();
            this.button_connect = new System.Windows.Forms.Button();
            this.textBox_password = new System.Windows.Forms.TextBox();
            this.textBox_user = new System.Windows.Forms.TextBox();
            this.label4 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.textBox_database = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.comboBox_sqls = new System.Windows.Forms.ComboBox();
            this.label1 = new System.Windows.Forms.Label();
            groupBox2 = new System.Windows.Forms.GroupBox();
            this.textBox_ExcelName = new System.Windows.Forms.TextBox();
            this.label9 = new System.Windows.Forms.Label();
            this.button_Excel = new System.Windows.Forms.Button();
            this.button1 = new System.Windows.Forms.Button();
            this.textBox_path = new System.Windows.Forms.TextBox();
            comboBox_tables = new System.Windows.Forms.ComboBox();
            this.label6 = new System.Windows.Forms.Label();
            this.label5 = new System.Windows.Forms.Label();
            groupBox3 = new System.Windows.Forms.GroupBox();
            this.button_Database = new System.Windows.Forms.Button();
            this.textBox_TableName = new System.Windows.Forms.TextBox();
            this.label8 = new System.Windows.Forms.Label();
            this.button2 = new System.Windows.Forms.Button();
            this.textBox_excel = new System.Windows.Forms.TextBox();
            this.label7 = new System.Windows.Forms.Label();
            this.ChooseExcelFile = new System.Windows.Forms.OpenFileDialog();
            this.label10 = new System.Windows.Forms.Label();
            this.textBox_IP = new System.Windows.Forms.TextBox();
            this.groupBox1.SuspendLayout();
            groupBox2.SuspendLayout();
            groupBox3.SuspendLayout();
            this.SuspendLayout();
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.textBox_IP);
            this.groupBox1.Controls.Add(this.label10);
            this.groupBox1.Controls.Add(this.button_disconnect);
            this.groupBox1.Controls.Add(this.button_connect);
            this.groupBox1.Controls.Add(this.textBox_password);
            this.groupBox1.Controls.Add(this.textBox_user);
            this.groupBox1.Controls.Add(this.label4);
            this.groupBox1.Controls.Add(this.label3);
            this.groupBox1.Controls.Add(this.textBox_database);
            this.groupBox1.Controls.Add(this.label2);
            this.groupBox1.Controls.Add(this.comboBox_sqls);
            this.groupBox1.Controls.Add(this.label1);
            this.groupBox1.Location = new System.Drawing.Point(12, 14);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(383, 110);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "连接数据库";
            // 
            // button_disconnect
            // 
            this.button_disconnect.Location = new System.Drawing.Point(297, 76);
            this.button_disconnect.Name = "button_disconnect";
            this.button_disconnect.Size = new System.Drawing.Size(75, 23);
            this.button_disconnect.TabIndex = 9;
            this.button_disconnect.Text = "断  开";
            this.button_disconnect.UseVisualStyleBackColor = true;
            this.button_disconnect.Click += new System.EventHandler(this.button_disconnect_Click);
            // 
            // button_connect
            // 
            this.button_connect.Location = new System.Drawing.Point(195, 76);
            this.button_connect.Name = "button_connect";
            this.button_connect.Size = new System.Drawing.Size(75, 23);
            this.button_connect.TabIndex = 8;
            this.button_connect.Text = "连  接";
            this.button_connect.UseVisualStyleBackColor = true;
            this.button_connect.Click += new System.EventHandler(this.button_connect_Click);
            // 
            // textBox_password
            // 
            this.textBox_password.Location = new System.Drawing.Point(243, 49);
            this.textBox_password.Name = "textBox_password";
            this.textBox_password.PasswordChar = '*';
            this.textBox_password.Size = new System.Drawing.Size(129, 21);
            this.textBox_password.TabIndex = 7;
            this.textBox_password.Text = "1324354657";
            // 
            // textBox_user
            // 
            this.textBox_user.Location = new System.Drawing.Point(63, 49);
            this.textBox_user.Name = "textBox_user";
            this.textBox_user.Size = new System.Drawing.Size(115, 21);
            this.textBox_user.TabIndex = 6;
            this.textBox_user.Text = "sa";
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(193, 55);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(53, 12);
            this.label4.TabIndex = 5;
            this.label4.Text = "密  码:";
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(16, 52);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(53, 12);
            this.label3.TabIndex = 4;
            this.label3.Text = "用户名:";
            // 
            // textBox_database
            // 
            this.textBox_database.Location = new System.Drawing.Point(63, 78);
            this.textBox_database.Name = "textBox_database";
            this.textBox_database.Size = new System.Drawing.Size(115, 21);
            this.textBox_database.TabIndex = 3;
            this.textBox_database.Text = "WarehouseDB";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(16, 81);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(53, 12);
            this.label2.TabIndex = 2;
            this.label2.Text = "数据库:";
            // 
            // comboBox_sqls
            // 
            this.comboBox_sqls.FormattingEnabled = true;
            this.comboBox_sqls.Items.AddRange(new object[] {
            "-- 请选择 --",
            "Mysql",
            "SQL Server",
            "Oracle"});
            this.comboBox_sqls.Location = new System.Drawing.Point(63, 17);
            this.comboBox_sqls.Name = "comboBox_sqls";
            this.comboBox_sqls.Size = new System.Drawing.Size(115, 20);
            this.comboBox_sqls.TabIndex = 1;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(16, 20);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(53, 12);
            this.label1.TabIndex = 0;
            this.label1.Text = "类  型:";
            // 
            // groupBox2
            // 
            groupBox2.Controls.Add(this.textBox_ExcelName);
            groupBox2.Controls.Add(this.label9);
            groupBox2.Controls.Add(this.button_Excel);
            groupBox2.Controls.Add(this.button1);
            groupBox2.Controls.Add(this.textBox_path);
            groupBox2.Controls.Add(comboBox_tables);
            groupBox2.Controls.Add(this.label6);
            groupBox2.Controls.Add(this.label5);
            groupBox2.Location = new System.Drawing.Point(12, 130);
            groupBox2.Name = "groupBox2";
            groupBox2.Size = new System.Drawing.Size(383, 99);
            groupBox2.TabIndex = 1;
            groupBox2.TabStop = false;
            groupBox2.Text = "数据表转Excel";
            // 
            // textBox_ExcelName
            // 
            this.textBox_ExcelName.Location = new System.Drawing.Point(99, 69);
            this.textBox_ExcelName.Name = "textBox_ExcelName";
            this.textBox_ExcelName.Size = new System.Drawing.Size(203, 21);
            this.textBox_ExcelName.TabIndex = 7;
            // 
            // label9
            // 
            this.label9.AutoSize = true;
            this.label9.Location = new System.Drawing.Point(16, 75);
            this.label9.Name = "label9";
            this.label9.Size = new System.Drawing.Size(83, 12);
            this.label9.TabIndex = 6;
            this.label9.Text = "文 件 名 称:";
            // 
            // button_Excel
            // 
            this.button_Excel.Location = new System.Drawing.Point(319, 28);
            this.button_Excel.Name = "button_Excel";
            this.button_Excel.Size = new System.Drawing.Size(53, 47);
            this.button_Excel.TabIndex = 5;
            this.button_Excel.Text = "导出";
            this.button_Excel.UseVisualStyleBackColor = true;
            this.button_Excel.Click += new System.EventHandler(this.button_Excel_Click);
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(265, 40);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(37, 23);
            this.button1.TabIndex = 4;
            this.button1.Text = "....";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // textBox_path
            // 
            this.textBox_path.Location = new System.Drawing.Point(99, 40);
            this.textBox_path.Name = "textBox_path";
            this.textBox_path.Size = new System.Drawing.Size(160, 21);
            this.textBox_path.TabIndex = 3;
            // 
            // comboBox_tables
            // 
            comboBox_tables.FormattingEnabled = true;
            comboBox_tables.Location = new System.Drawing.Point(99, 14);
            comboBox_tables.Name = "comboBox_tables";
            comboBox_tables.Size = new System.Drawing.Size(203, 20);
            comboBox_tables.TabIndex = 2;
            comboBox_tables.SelectedIndexChanged += new System.EventHandler(this.comboBox_tables_SelectedIndexChanged);
            // 
            // label6
            // 
            this.label6.AutoSize = true;
            this.label6.Location = new System.Drawing.Point(16, 43);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(83, 12);
            this.label6.TabIndex = 1;
            this.label6.Text = "存 储 位 置:";
            // 
            // label5
            // 
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(16, 17);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(83, 12);
            this.label5.TabIndex = 0;
            this.label5.Text = "选择 数据表:";
            // 
            // groupBox3
            // 
            groupBox3.Controls.Add(this.button_Database);
            groupBox3.Controls.Add(this.textBox_TableName);
            groupBox3.Controls.Add(this.label8);
            groupBox3.Controls.Add(this.button2);
            groupBox3.Controls.Add(this.textBox_excel);
            groupBox3.Controls.Add(this.label7);
            groupBox3.Location = new System.Drawing.Point(13, 235);
            groupBox3.Name = "groupBox3";
            groupBox3.Size = new System.Drawing.Size(382, 80);
            groupBox3.TabIndex = 2;
            groupBox3.TabStop = false;
            groupBox3.Text = "Excel转数据表";
            // 
            // button_Database
            // 
            this.button_Database.Location = new System.Drawing.Point(318, 20);
            this.button_Database.Name = "button_Database";
            this.button_Database.Size = new System.Drawing.Size(53, 51);
            this.button_Database.TabIndex = 5;
            this.button_Database.Text = "导入";
            this.button_Database.UseVisualStyleBackColor = true;
            this.button_Database.Click += new System.EventHandler(this.button_Database_Click);
            // 
            // textBox_TableName
            // 
            this.textBox_TableName.Location = new System.Drawing.Point(98, 50);
            this.textBox_TableName.Name = "textBox_TableName";
            this.textBox_TableName.Size = new System.Drawing.Size(203, 21);
            this.textBox_TableName.TabIndex = 4;
            // 
            // label8
            // 
            this.label8.AutoSize = true;
            this.label8.Location = new System.Drawing.Point(15, 53);
            this.label8.Name = "label8";
            this.label8.Size = new System.Drawing.Size(65, 12);
            this.label8.TabIndex = 3;
            this.label8.Text = "数据表名:";
            // 
            // button2
            // 
            this.button2.Location = new System.Drawing.Point(264, 18);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(37, 23);
            this.button2.TabIndex = 2;
            this.button2.Text = "....";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // textBox_excel
            // 
            this.textBox_excel.Location = new System.Drawing.Point(98, 20);
            this.textBox_excel.Name = "textBox_excel";
            this.textBox_excel.ReadOnly = true;
            this.textBox_excel.Size = new System.Drawing.Size(160, 21);
            this.textBox_excel.TabIndex = 1;
            // 
            // label7
            // 
            this.label7.AutoSize = true;
            this.label7.Location = new System.Drawing.Point(15, 26);
            this.label7.Name = "label7";
            this.label7.Size = new System.Drawing.Size(65, 12);
            this.label7.TabIndex = 0;
            this.label7.Text = "选择文件:";
            // 
            // ChooseExcelFile
            // 
            this.ChooseExcelFile.Filter = "Excel 文件(*.xls;*xlsx)|*.xls;*xlsx;";
            // 
            // label10
            // 
            this.label10.AutoSize = true;
            this.label10.Location = new System.Drawing.Point(193, 20);
            this.label10.Name = "label10";
            this.label10.Size = new System.Drawing.Size(53, 12);
            this.label10.TabIndex = 10;
            this.label10.Text = "IP地址:";
            // 
            // textBox_IP
            // 
            this.textBox_IP.Location = new System.Drawing.Point(243, 17);
            this.textBox_IP.Name = "textBox_IP";
            this.textBox_IP.Size = new System.Drawing.Size(129, 21);
            this.textBox_IP.TabIndex = 11;
            this.textBox_IP.Text = "127.0.0.1";
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(407, 321);
            this.Controls.Add(groupBox3);
            this.Controls.Add(groupBox2);
            this.Controls.Add(this.groupBox1);
            this.Name = "Form1";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Excel与数据库互相转换";
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            groupBox2.ResumeLayout(false);
            groupBox2.PerformLayout();
            groupBox3.ResumeLayout(false);
            groupBox3.PerformLayout();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.ComboBox comboBox_sqls;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.TextBox textBox_database;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.TextBox textBox_password;
        private System.Windows.Forms.TextBox textBox_user;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.Button button_disconnect;
        private System.Windows.Forms.Button button_connect;
        private static System.Windows.Forms.GroupBox groupBox2;
        private System.Windows.Forms.Button button_Excel;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.TextBox textBox_path;
        private System.Windows.Forms.Label label6;
        private System.Windows.Forms.Label label5;
        private static System.Windows.Forms.GroupBox groupBox3;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Button button_Database;
        private System.Windows.Forms.TextBox textBox_TableName;
        private System.Windows.Forms.Label label8;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.TextBox textBox_excel;
        private System.Windows.Forms.Label label7;
        private System.Windows.Forms.OpenFileDialog ChooseExcelFile;
        private System.Windows.Forms.TextBox textBox_ExcelName;
        private System.Windows.Forms.Label label9;
        private System.Windows.Forms.TextBox textBox_IP;
        private System.Windows.Forms.Label label10;
        private static System.Windows.Forms.ComboBox comboBox_tables;
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值