📄 import.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using System.Data.OracleClient;
using Excel;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Configuration;
namespace Reset
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class ImportExcel : System.Windows.Forms.Form
{
public bool a = false;
private System.Data.OracleClient.OracleConnection oracleConnection1;
private System.Windows.Forms.Button btnImport;
private System.Windows.Forms.ComboBox cbxPhone;
private System.Windows.Forms.Label lblPhone;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox txtPath;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public ImportExcel()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.oracleConnection1 = new System.Data.OracleClient.OracleConnection();
this.btnImport = new System.Windows.Forms.Button();
this.cbxPhone = new System.Windows.Forms.ComboBox();
this.lblPhone = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.txtPath = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// oracleConnection1
//
this.oracleConnection1.ConnectionString = "user id=telbizusr;data source=orcl;password=njtu";
//
// btnImport
//
this.btnImport.Location = new System.Drawing.Point(160, 128);
this.btnImport.Name = "btnImport";
this.btnImport.Size = new System.Drawing.Size(64, 24);
this.btnImport.TabIndex = 0;
this.btnImport.Text = "导入";
this.btnImport.Click += new System.EventHandler(this.btnImport_Click);
//
// cbxPhone
//
this.cbxPhone.Items.AddRange(new object[] {
"交接箱",
"分歧头",
"分线盒"});
this.cbxPhone.Location = new System.Drawing.Point(32, 56);
this.cbxPhone.Name = "cbxPhone";
this.cbxPhone.Size = new System.Drawing.Size(121, 20);
this.cbxPhone.TabIndex = 1;
//
// lblPhone
//
this.lblPhone.Location = new System.Drawing.Point(32, 24);
this.lblPhone.Name = "lblPhone";
this.lblPhone.Size = new System.Drawing.Size(72, 16);
this.lblPhone.TabIndex = 2;
this.lblPhone.Text = "设备类型:";
//
// button1
//
this.button1.Location = new System.Drawing.Point(136, 200);
this.button1.Name = "button1";
this.button1.TabIndex = 3;
this.button1.Text = "导出";
//
// txtPath
//
this.txtPath.Location = new System.Drawing.Point(216, 64);
this.txtPath.Name = "txtPath";
this.txtPath.TabIndex = 4;
this.txtPath.Text = "c:\\交接箱分歧头分线盒.xls";
//
// ImportExcel
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(376, 296);
this.Controls.Add(this.txtPath);
this.Controls.Add(this.button1);
this.Controls.Add(this.lblPhone);
this.Controls.Add(this.cbxPhone);
this.Controls.Add(this.btnImport);
this.MaximizeBox = false;
this.Name = "ImportExcel";
this.Text = "ImportExcel";
this.Load += new System.EventHandler(this.reset_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Login login = new Login( );
login.ShowDialog();
if ( login.DialogResult == DialogResult.OK )
System.Windows.Forms.Application.Run(new ImportExcel() );
}
private void reset_Load(object sender, System.EventArgs e)
{
}
private void btnImport_Click(object sender, System.EventArgs e)
{
importExcel();
}
private DataSet importExcel()
{
/* myOleCon.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";
myOleCon.ConnectionString+=fi.FullName;\\文件全名带路径
myOleCon.ConnectionString+=";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\"" ; //use it like DB
SQL like//sqlStr= "select * from [sheet1$]";//EXCEL就是数据库,每个sheet就是表 */
string strCon;
strCon="Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=\"Excel 8.0;HDR=yes\";Data Source='"+txtPath.Text+"'";
OleDbConnection olecon=new OleDbConnection(strCon);
OleDbDataAdapter myda=new OleDbDataAdapter("SELECT * FROM [Sheet1$]",strCon);
DataSet myds=new DataSet();
myda.Fill(myds);
return myds;
}
// oracleConnection1.Open();
// string _select= "select NAME from TB_PHONECONNECTBOX";
// OracleDataAdapter da = new OracleDataAdapter(_select,oracleConnection1);
// DataSet ds = new DataSet();
// da.Fill(ds);
//
// string strConn = "Provider=Microsoft.Jet.OLEDB.5.0;"
// +"Data Source=" + this.txtPath.Text + ";"
// +"Extended Properties=\"Excel 11.0\";";
// //Excel.Application xlApp=new Excel.Application();
//
// try
// {
// OleDbConnection cn = new OleDbConnection(strConn);
// cn.Open();
// }
// catch
// {
// MessageBox.Show("Connection to DataBase Error!");
// return;
// }
//
//
// }
private void outportExcel()
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -