首页 > 学院 > 开发设计 > 正文

用C#读取excel中的数据,并绘制曲线

2019-11-10 19:42:38
字体:
来源:转载
供稿:网友
using System;using System.Windows.Forms;using Microsoft.Office.Interop.Excel;namespace WindowsFormsapplication1{ public partial class Form1 : Form { PRivate static Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); private static Workbooks workbooks = excel.Workbooks; private static string strFileFullName = @"C:/Users/PC-0424/Desktop/test.xlsx"; private static Workbook book = workbooks.Open(strFileFullName, 0, false, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false); private static Worksheet sheet = (Worksheet)book.Worksheets["Sheet1"]; Random random = new Random(); private static int a = 1; private static int b = 0; public Form1() { InitializeComponent(); } private void timer1_Tick(object sender, EventArgs e) { Range rng = sheet.Cells[a, 1]; if (rng.Value2 != null) { this.chart1.Series[0].Points.AddXY(b, rng.Value2); a++; b++; } else timer1.Stop(); } }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表