Overview

This document provides an instructional guide on how to export a Historian Database into a CSV file using SQL Server Historian. This is particularly useful for retrieving older, archived data in Excel. This guide provides a line of code to be used in CodeBehind, which, upon a button click, triggers the export of data into an Excel file.

  

On this page:


Export the Historian Database into an CSV File

To retrieve older data that has been archived using SQL Server Historian in Excel, follow the steps below:



To save the historian database to an Excel file, write the following line of code in CodeBehind and set it up so that when the button is clicked, the code is executed:

public void MouseLeftButtonDown1(object sender, System.Windows.Input.InputEventArgs e)
{
	var nowDate = new DateTime(2023, 7, 2, 22, 59, 59);
	var startDate = new DateTime(2021, 7, 2, 22, 59, 59);

	@Historian.Table.Table1.SaveToTextFile(startDate, nowDate, "HistorianFileSave", ";", true, true, false, 2, null);
}


The result will be the data exported as follows:


To access a project example that presents an out-of-box solution for exporting historical data to CSV files, visit the project example : Historian - Export to CSV - v10



In this section...

  • No labels