C#用winform实现excel数据合并

1、问题描述

       一共有3表,A是源操作表,B、C目的操作表。A B C 中都有两个个相同的字段。问题:现在用A中的这个关键字段分别去B和C中取得对应项的数据,在写回A表中的对应的另外一个字段。

         这个工具目前设定的是;操作excel表,文件格式:.csv  | .xls 

2、结果

    

   点击确定,完成转换。


3、代码

     A、打开工具箱:添加openFileDialog控件,命名采用默认的就行了。

     B、这次的代码做了stylecop规范检查。

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

namespace ModifyData
{
    /// <summary>
    ///  窗口类
    /// </summary>
    public partial class Form1 : Form
    {
        #region private member
        /// <summary>
        /// 新建文件保存路径
        /// </summary>
        private string savePath = string.Empty;

        /// <summary>
        /// CSV文件数据集
        /// </summary>
        private DataSet fundCSVDs = null;

        /// <summary>
        /// 交易支付数据集
        /// </summary>
        private DataSet payXLSDs = null;

        /// <summary>
        /// 交易退款数据集
        /// </summary>
        private DataSet backXLSDs = null;

        /// <summary>
        ///  数据库连接
        /// </summary>
        private OleDbConnection conn;

        /// <summary>
        /// 源文件
        /// </summary>
        private string orinFileName = string.Empty;

        /// <summary>
        /// 目标文件
        /// </summary>
        private string[] aimFileName = new string[2];

        /// <summary>
        /// 批量读取
        /// </summary>
        private string[] everyRead = new string[300];
        #endregion

        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary>
        public Form1()
        {
            this.InitializeComponent();
            tbOrign.ReadOnly = true;
            tbAim1.ReadOnly = true;
            tbAim2.ReadOnly = true;
        }
        #endregion

        #region 控件方法
        /// <summary>
        /// 添加源浏览文件
        /// </summary>
        /// <param name="sender">消息对象</param>
        /// <param name="e">消息体</param>
        private void BtnOrinSelect_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "Excel表格(CSV格式(*.csv)|*.csv";
            openFileDialog1.FileName = string.Empty;
            openFileDialog1.ShowDialog();
            string selectFileName = openFileDialog1.FileName;

            // 获取保存文件名路径
            this.savePath = selectFileName;

            tbOrign.Text = selectFileName;

            // 获取文件名
            this.orinFileName = tbOrign.Text.Remove(0, selectFileName.LastIndexOf("\\") + 1);
        }

        /// <summary>
        /// 添加目的文件1
        /// </summary>
        /// <param name="sender">消息对象</param>
        /// <param name="e">消息体</param>
        private void BtnAim1_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "Excel表格(*.xls)|*.xls";
            openF
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值