已经可以从WINCC的归档数据库获取数据,并且以图形的方式显示出来了。
现在要实现一个功能,就是建一个相当于WINCC历史趋势的标尺,移动后,下面显示数据,点击按钮,记录这组数据。
获取的数据,可以进行后面的处理,比如作为神经网络的输入数据。
下面对各个例子记录实现过程。
1. 在excel 中实现数据处理:
新增功能:Excel_A1
最终的结果如下:
2. 添加引用
Spire 功能如此强大
运行后出现:
这个控件有问题,需要收费,换一个试试
3. 卸载Spire.XLS 后,安装FreeSpire.XLS 试一下:
运行结果如下:
Workbook workbook = new Workbook(); workbook.CreateEmptySheets(1); Worksheet sheet = workbook.Worksheets[0]; sheet.Name = "Demo"; sheet.Range["A1"].Value = "Month"; sheet.Range["A2"].Value = "Jan."; sheet.Range["A3"].Value = "Feb."; sheet.Range["A4"].Value = "Mar."; sheet.Range["A5"].Value = "Apr."; sheet.Range["A6"].Value = "May."; sheet.Range["A7"].Value = "Jun."; sheet.Range["B1"].Value = "Peter"; sheet.Range["B2"].NumberValue = 3.3; sheet.Range["B3"].NumberValue = 2.5; sheet.Range["B4"].NumberValue = 2.0; sheet.Range["B5"].NumberValue = 3.7; sheet.Range["B6"].NumberValue = 4.5; sheet.Range["B7"].NumberValue = 4.0; sheet.Range["C1"].Value = "George"; sheet.Range["C2"].NumberValue = 3.8; sheet.Range["C3"].NumberValue = 3.2; sheet.Range["C4"].NumberValue = 1.7; sheet.Range["C5"].NumberValue = 3.5; sheet.Range["C6"].NumberValue = 4.5; sheet.Range["C7"].NumberValue = 4.3; sheet.Range["D1"].Value = "Macbeth"; sheet.Range["D2"].NumberValue = 3.0; sheet.Range["D3"].NumberValue = 2.8; sheet.Range["D4"].NumberValue = 3.5; sheet.Range["D5"].NumberValue = 2.3; sheet.Range["D6"].NumberValue = 3.3; sheet.Range["D7"].NumberValue = 3.8; Chart chart = sheet.Charts.Add(ExcelChartType.Column3DClustered); chart.DataRange = sheet.Range["B1:D7"]; chart.SeriesDataFromRange = false; chart.TopRow = 7; chart.BottomRow = 28; chart.LeftColumn = 3; chart.RightColumn = 11; chart.ChartTitle = "Chart with Data Table"; chart.ChartTitleArea.IsBold = true; chart.ChartTitleArea.Size = 12; Spire.Xls.Charts.ChartSerie cs1 = chart.Series[0]; cs1.CategoryLabels = sheet.Range["A2:A7"]; chart.HasDataTable = true; workbook.SaveToFile("S3.xlsx", ExcelVersion.Version2010); System.Diagnostics.Process.Start("S3.xlsx");
4. 小结
4.1 这个功能很强大,处理excel 比原来的程序简单;
4.2 和excel 结合处理数据,也许更加方便;
4.3 对这个程序进行修改,实现一些其它的功能
标签:sheet,NumberValue,C#,chart,Value,获取数据,Range,workbook From: https://www.cnblogs.com/jihhh/p/17438789.html