Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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. The 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:

Table of Contents
maxLevel3

Tip
titleSolution Example

Export Historian to CSV Example.



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:Image Removed

Code Block
languagec#
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 solution example that presents an out-of-box solution for exporting historical data to CSV files, visit: Export Historian - Export to CSV - 9.2 (LINK TO 9.2, NEED TO UPDATE THE TPROJ TO V10)Example.



In this section...

Page Tree
root@parent
spacesV10