• 大小: 202KB
    文件类型: .rar
    金币: 2
    下载: 2 次
    发布日期: 2021-06-18
  • 语言: C#
  • 标签: C#、chart  

资源简介

C#读取excel、csv等文件到chart折线图,有详细的代码注释

资源截图

代码片段和文件信息

using Microsoft.Office.Interop.Excel;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public static Form1 form1;
        private static System.Data.DataTable sourceDT;
        public Form1()
        {
            InitializeComponent();
            this.panel2.Visible = false;
            form1 = this;
        }

        private void button1_Click(object sender EventArgs e)
        {

        }
        private void Form1_Load(object sender EventArgs e)
        {
            for (int i = 1; i < 41; i++)
            {
                cmbChanel.Items.Add(i);

            }
            cmbChanel.SelectedIndex = 0;
        }


        private void OpenExcel(string strFileName)
        {
            object missing = System.Reflection.Missing.Value;
            Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();//lauch excel application
            if (excel == null)
            {
                //Response.Write(“ript>alert(‘Can‘t access excel‘)ript>“);
            }
            else
            {
                excel.Visible = false; excel.UserControl = true;
                // 以只读的形式打开EXCEL文件
                Workbook wb = excel.Application.Workbooks.Open(strFileName missing true missing missing missing
                 missing missing missing true missing missing missing missing missing);
                //取得第一个工作薄
                Worksheet ws = (Worksheet)wb.Worksheets.get_Item(1);


                //取得总记录行数   (包括标题列)
                int rowsint = ws.UsedRange.Cells.Rows.Count; //得到行数
                int columnsint = ws.UsedRange.Cells.Columns.Count;//得到列数


                //取得数据范围区域 (不包括标题列) 
                Range rng1 = ws.Cells.get_Range(“A17“ “A“ + rowsint);   //item


                Range rng2 = ws.Cells.get_Range(“B17“ “B“ + rowsint); //Customer
                double[] arryItem = (double[])rng1.Value2;   //get range‘s value
                double[] arryCus = (double[])rng2.Value2;
                System.Data.DataTable dt = new System.Data.DataTable(“data“);
                dt.Columns.Add(“Wavelength“ Type.GetType(“System.Int32“));
                dt.Columns.Add(“Merge“ Type.GetType(“System.Int32“));
                double[] Wavelength = dt.AsEnumerable().Select(d => d.Field(“Wavelength“)).ToArray();
                double[] Merge = dt.AsEnumerable().Select(d => d.Field(“Merge1“)).ToArray();

                //将新值赋给一个数组
                string[] arry = new string[rowsin

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        187  2018-01-16 14:54  text\test\test\WindowsFormsApplication1\App.config

     文件      49152  2018-02-02 09:12  text\test\test\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe

     文件        187  2018-01-16 14:54  text\test\test\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe.config

     文件      50688  2018-02-02 09:12  text\test\test\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.pdb

     文件      22984  2018-02-02 08:35  text\test\test\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe

     文件        187  2018-01-16 14:54  text\test\test\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe.config

     文件        490  2013-06-18 20:28  text\test\test\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe.manifest

     文件      10689  2018-02-02 09:53  text\test\test\WindowsFormsApplication1\Form1.cs

     文件      10071  2018-02-02 09:53  text\test\test\WindowsFormsApplication1\Form1.Designer.cs

     文件       5817  2018-02-02 09:53  text\test\test\WindowsFormsApplication1\Form1.resx

     文件       9917  2018-02-01 10:07  text\test\test\WindowsFormsApplication1\Form2.cs

     文件      73201  2018-02-01 10:07  text\test\test\WindowsFormsApplication1\Form2.Designer.cs

     文件       5817  2018-02-01 10:07  text\test\test\WindowsFormsApplication1\Form2.resx

     文件        863  2018-02-02 08:35  text\test\test\WindowsFormsApplication1\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       7260  2018-02-02 08:35  text\test\test\WindowsFormsApplication1\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件          0  2018-01-16 14:54  text\test\test\WindowsFormsApplication1\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

     文件          0  2018-01-16 14:54  text\test\test\WindowsFormsApplication1\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

     文件          0  2018-01-16 14:54  text\test\test\WindowsFormsApplication1\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

     文件       5239  2018-02-02 09:12  text\test\test\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.csproj.FileListAbsolute.txt

     文件       1033  2018-02-02 09:12  text\test\test\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.csproj.GenerateResource.Cache

     文件      49152  2018-02-02 09:12  text\test\test\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.exe

     文件        180  2018-02-02 09:12  text\test\test\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.Form1.resources

     文件        180  2018-02-02 09:12  text\test\test\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.Form2.resources

     文件      50688  2018-02-02 09:12  text\test\test\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.pdb

     文件        180  2018-02-02 09:12  text\test\test\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.Properties.Resources.resources

     文件        536  2018-01-16 14:54  text\test\test\WindowsFormsApplication1\Program.cs

     文件       1368  2018-01-16 14:54  text\test\test\WindowsFormsApplication1\Properties\AssemblyInfo.cs

     文件       2900  2018-01-16 14:54  text\test\test\WindowsFormsApplication1\Properties\Resources.Designer.cs

     文件       5612  2018-01-16 14:54  text\test\test\WindowsFormsApplication1\Properties\Resources.resx

     文件       1111  2018-01-16 14:54  text\test\test\WindowsFormsApplication1\Properties\Settings.Designer.cs

............此处省略64个文件信息

评论

共有 条评论

相关资源