C# Using data from Excel to simulate a Signal over

2019-08-21 20:22发布

问题:

is there any good way how i can import a Excel file with signal values (40,000 values, ~100 minutes measurement time) and simulate a signal over time with it?

I want to reconstruct the simulation with timestamp and Signal values.

I've two columns:

  • Timestamp for every value (it isn't equidistant)
  • Signal-Value

The timestamp should be nearly synchron with the simulationtime.

Maybe someone has a good "to start" idea?

Thank you!

Update #1 (based on the comments):

@Wouter de Kort: I got data from measurement over time. I got for every timestamp a value. The data looks something like this (without backslash):

Time (s) // Value

154,51 // 49,33

154,71 // 49,46

154,92 // 49,72

155,11 // 49,64

I only want to look from the beginning to the end of the data over a time (the time, the measurement in real took). Like a Sinus Generator, but in this case i've a specific signal and the values has to be at a specific time.

How can i export it to CSV? And what are the benefits using CSV with C# instead of Excel?

Update #2:

My case is, to get every (e.g.) 100ms a new value through a variable which i can use for my visualization program i already have.

回答1:

Take a look at this: Importing Excel into a DataTable Quickly There's an importing example directly from an Excel spreadsheet without the need to convert to CSV.

You can also use OfficeOpenXml. It provides a way to access cell data like so:

using OfficeOpenXml;
...
var pck = new ExcelPackage(fileName);
var ws = pck.Workbook.Worksheets.ElementAt(0);  // first worksheet
ws.Select();
var value = ws.Cells[row, col].Value;           // corresponds to some Excel cell value