• 大小: 88.54MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-01-28
  • 语言: C#
  • 标签: C#  EXCEL  C#EXCEL  

资源简介

C#使用Microsoft.Office.Interop.Excel操作EXCEL,读取EXCEL到内存中,处理完存到新的EXCEL中。程序逻辑是根据工程内“初始文件”文件夹编写的,所以请使用初始文件里的文件操作。处理完例子文件可能需十来分钟。当然,可以只看代码里面是怎么使用Microsoft.Office.Interop.Excel的。另,编码水平有限,慎下载。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Interop.Excel;

namespace ExcelProcess
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            memoEdit1.Text += “...“;
            memoEdit1.Text += “\r\n“ + “请选择文件...“;
        }

        private void button1_Click(object sender EventArgs e)
        {
            //要求:这里Time是2002-01~2018-12,总共是17*12=204个月,要求每个月只占一行,就是总共只有204行,每一行依次(必按此顺序)包含Value1-ValueNReturn1-ReturnNBeta1-BetaN,BtoM1-BtoMNLeve1-LeveN。                            可行?先按照Time读入一些数据,然后遇到Time不同的,就开始按列输出,然后输入换行符?结构体数组?
            
            if(txtNUM.Text != null)
            {
                if(!string.IsNullOrWhiteSpace(txtYuan.Text))
                {
                    if (!string.IsNullOrWhiteSpace(txtSave.Text))
                    {
                        //memoEdit1.Selectionstart = memoEdit1.Text.Length;//做笔记--定位到字符串最末尾
                        ProcessDataNew editExcel = new ProcessDataNew(Convert.ToInt32(txtNUM.Text) txtYuan.Text txtSave.Text);//调用构造函数中赋值
                        memoEdit1.Text += “\r\n“ + “开始转换...“;
                        editExcel.getColumnDB();//读数据
                        memoEdit1.Text += “\r\n“ + “读取完成,开始转化并保存到EXCEL...“;
                        editExcel.setToExcel();//写数据
                        memoEdit1.Text += “\r\n“ + “转化完成“;
                    }
                }
            }
            
            //editExcel.getColumnDB(importExcelPath);
            //editExcel.setToExcelNULL();
        }
        

        private void button2_Click(object sender EventArgs e)//浏览按钮事件
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                txtYuan.Text = openFileDialog.FileName;//
            }
        }

        private void button3_Click(object sender EventArgs e)//另一个浏览按钮事件
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                txtSave.Text = openFileDialog.FileName;//需要新建一个EXCEL,并且注意Sheet名字与setToExcel()中的一致
            }
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-07-18 12:26  ExcelProcess\
     目录           0  2019-07-18 12:19  ExcelProcess\.vs\
     目录           0  2019-07-18 12:19  ExcelProcess\.vs\ExcelProcess\
     目录           0  2019-07-18 12:19  ExcelProcess\.vs\ExcelProcess\v15\
     文件      222720  2019-08-02 15:10  ExcelProcess\.vs\ExcelProcess\v15\.suo
     目录           0  2019-07-18 12:19  ExcelProcess\.vs\ExcelProcess\v15\Server\
     目录           0  2019-07-22 11:19  ExcelProcess\.vs\ExcelProcess\v15\Server\sqlite3\
     文件           0  2019-07-18 12:19  ExcelProcess\.vs\ExcelProcess\v15\Server\sqlite3\db.lock
     文件     1327104  2019-07-25 10:32  ExcelProcess\.vs\ExcelProcess\v15\Server\sqlite3\storage.ide
     文件       32768  2019-08-02 14:58  ExcelProcess\.vs\ExcelProcess\v15\Server\sqlite3\storage.ide-shm
     文件     4132392  2019-08-02 15:10  ExcelProcess\.vs\ExcelProcess\v15\Server\sqlite3\storage.ide-wal
     目录           0  2019-08-02 15:09  ExcelProcess\ExcelProcess\
     文件        1134  2019-07-18 12:19  ExcelProcess\ExcelProcess.sln
     目录           0  2019-07-25 10:56  ExcelProcess\ExcelProcess\bin\
     目录           0  2019-07-18 13:02  ExcelProcess\ExcelProcess\bin\Debug\
     文件     7093782  2019-07-25 10:56  ExcelProcess\ExcelProcess\bin\Debug.zip
     目录           0  2019-07-18 13:02  ExcelProcess\ExcelProcess\bin\Debug\de\
     文件     3243512  2018-10-09 10:29  ExcelProcess\ExcelProcess\bin\Debug\DevExpress.Data.v13.2.dll
     文件     1034398  2018-10-09 10:29  ExcelProcess\ExcelProcess\bin\Debug\DevExpress.Data.v13.2.xml
     文件     2443256  2018-10-09 10:29  ExcelProcess\ExcelProcess\bin\Debug\DevExpress.Printing.v13.2.Core.dll
     文件      865532  2018-10-09 10:29  ExcelProcess\ExcelProcess\bin\Debug\DevExpress.Printing.v13.2.Core.xml
     文件       43512  2018-10-09 10:29  ExcelProcess\ExcelProcess\bin\Debug\DevExpress.Sparkline.v13.2.Core.dll
     文件       20893  2018-10-09 10:29  ExcelProcess\ExcelProcess\bin\Debug\DevExpress.Sparkline.v13.2.Core.xml
     文件     4868600  2018-10-09 10:29  ExcelProcess\ExcelProcess\bin\Debug\DevExpress.Utils.v13.2.dll
     文件      512041  2018-10-09 10:29  ExcelProcess\ExcelProcess\bin\Debug\DevExpress.Utils.v13.2.xml
     文件     2724344  2018-10-09 10:29  ExcelProcess\ExcelProcess\bin\Debug\DevExpress.XtraEditors.v13.2.dll
     文件     1423737  2018-10-09 10:29  ExcelProcess\ExcelProcess\bin\Debug\DevExpress.XtraEditors.v13.2.xml
     文件      165368  2018-10-09 10:29  ExcelProcess\ExcelProcess\bin\Debug\de\DevExpress.Data.v13.2.resources.dll
     文件       12792  2018-10-09 10:29  ExcelProcess\ExcelProcess\bin\Debug\de\DevExpress.Printing.v13.2.Core.resources.dll
     文件       11256  2018-10-09 10:29  ExcelProcess\ExcelProcess\bin\Debug\de\DevExpress.Sparkline.v13.2.Core.resources.dll
     文件       25592  2018-10-09 10:29  ExcelProcess\ExcelProcess\bin\Debug\de\DevExpress.Utils.v13.2.resources.dll
............此处省略78个文件信息

评论

共有 条评论