C#数据转换前excel中的数据格式如下:
设备名称 规格型号 设备编号 使用部门 固定资产编号
电脑1 IBM5660 10001 管理部 100010001
电脑2 IBM5661 10002 研发部 100010002
电脑3 IBM5662 10003 管理部 100010003
C#数据转换到TXT文档的格式:
"检测设备资产标签","设备名称","电脑1","规格型号","IBM5660","设备编号","10001","使用部门","管理部","固定资产编号","100010001"
"检测设备资产标签","设备名称","电脑2","规格型号","IBM5661","设备编号","10002","使用部门","研发部","固定资产编号","100010002"
"检测设备资产标签","设备名称","电脑3","规格型号","IBM5662","设备编号","10003","使用部门","管理部","固定资产编号","100010003"
end
页面设计代码:
复制代码 代码如下:
namespace ExcelToTxt
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param>如果应释放托管资源,为 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.dgvShow = new System.Windows.Forms.DataGridView();
this.btnSelect = new System.Windows.Forms.Button();
this.btnChange = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dgvShow)).BeginInit();
this.SuspendLayout();
//
// dgvShow
//
this.dgvShow.AllowUserToAddRows = false;
this.dgvShow.AllowUserToDeleteRows = false;
this.dgvShow.AllowUserToResizeRows = false;
this.dgvShow.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgvShow.Dock = System.Windows.Forms.DockStyle.Top;
this.dgvShow.Location = new System.Drawing.Point(0, 0);
this.dgvShow.Name = "dgvShow";
this.dgvShow.RowTemplate.Height = 23;
this.dgvShow.Size = new System.Drawing.Size(885, 600);
this.dgvShow.TabIndex = 0;
//
// btnSelect
//
this.btnSelect.Location = new System.Drawing.Point(202, 611);
this.btnSelect.Name = "btnSelect";
this.btnSelect.Size = new System.Drawing.Size(148, 23);
this.btnSelect.TabIndex = 1;
this.btnSelect.Text = "选择excel文件";
this.btnSelect.UseVisualStyleBackColor = true;
this.btnSelect.Click += new System.EventHandler(this.btnSelect_Click);
//
// btnChange
//
this.btnChange.Location = new System.Drawing.Point(403, 611);
this.btnChange.Name = "btnChange";
this.btnChange.Size = new System.Drawing.Size(152, 23);
this.btnChange.TabIndex = 2;
this.btnChange.Text = "转换为txt文档";
this.btnChange.UseVisualStyleBackColor = true;
this.btnChange.Click += new System.EventHandler(this.btnChange_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(885, 646);
this.Controls.Add(this.btnChange);
this.Controls.Add(this.btnSelect);
this.Controls.Add(this.dgvShow);
this.Name = "Form1";
this.Text = "文件转换";
((System.ComponentModel.ISupportInitialize)(this.dgvShow)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.DataGridView dgvShow;
private System.Windows.Forms.Button btnSelect;
private System.Windows.Forms.Button btnChange;
}
}
C#数据转换实现代码:
复制代码 代码如下: