在我的WPF MVVM Prism應用程序中,我每秒從外部設備讀取一些數據(通過COM端口)(我使用System.Windows.Threading.DispatcherTimer)。每次我的數據填充以下緩衝區讀取:如何將DateTime,TimeSpan,字符串和雙精度值從WPF MVVM應用程序導出到Excel中?
/// <summary>
/// Represents the point on the chart.
/// </summary>
public class ChartPoint
{
#region Fields
// The value from outer device.
private double _value;
// The date and time when the value was being obtained.
private DateTime _category;
#endregion
#region Constructors
public ChartPoint() { }
public ChartPoint(DateTime category, double value)
{
this.Category = category;
this.Value = value;
}
#endregion
#region Properties
public double Value
{
get { return this._value; }
set
{
if (double.IsNaN(value) || double.IsInfinity(value))
value = 0;
this._value = value;
}
}
public DateTime Category
{
get { return this._category; }
set { this._category = value; }
}
#endregion
}
我需要導出到Microsoft Excel中的以下數據:
DateTime currentDate = ChartPoint.Category.Date;
TimeSpan currentTime = ChartPoint.Category.TimeOfDay;
double currentValue = ChartPoint.Value;
的時間值必須在用戶員工共贏視圖,例如: 09:21:54(hh:mm:ss)。這裏必須添加測量超聲波束的名稱。例如:
string measuringBeam = "beam 1";
or
string measuringBeam = "beam 2";
等,梁的總數 - 八(8)。因此,MS Excel表格中每一行的格式必須爲:
____________________________________________________________
| Current Date | Current Time | Measuring Beam | The Value |
------------------------------------------------------------
| 04.10.2016 | 09:21:54 | beam 1 | 347.25 |
------------------------------------------------------------
. . . . . . . . . . . . . and so on. . . . . . . . . . . .
我認爲在每個計時器中應該創建下一行。因此,我需要以編程方式創建包含具有上述格式的表格的MS Excel文件,將該文件保存在特定文件夾中,然後在其中添加新行。我認爲提高出口率應該不是每行一行,而是每十行甚至每百行。也就是說,一旦創建了下一百行,它就存儲在Excel文件中。整個導出操作將通過選擇相應的下拉菜單項並以相同的方式停止運行。每次導出啓動時,都必須創建一個用於導出數據的新Excel文件。在使用VSTO之前,我無法使用Excel對象模型。但現在遇到這種必要性。我開始閱讀MSDN的VSTO,但是由於創建我的應用程序,我非常擁擠。請幫助創建導出到Excel。良好的榜樣將會是偉大的。您的幫助將受到高度讚賞。
非常感謝Panagiotis Kanavos,但我希望看到VSTO Excel對象模型適用於我的案例。 – Prohor
VSTO旨在創建插件和宏,而不是生成Excel文件。如果要將1000行導出到Excel文件,VSTO不會幫助您。這些插件需要安裝Excel才能運行。這不是問題所在,除非在最後一段中提到了這一點。 –
EPPlus對我的需求是真正的好東西。我在哪裏可以找到有關探索EPPLus的文檔? – Prohor