CSV
public class CSVDocument
-
With the CSV adapter you can export a csv file with a specific content.
Methods
CSVDocument(string Delimiter = ";", string stringEscape="\"", string Escape="\\", string LineBreak = "\r\n")
-
The constructor
void SetValue(int row, int col, object value)
-
Sets a value into a specified row and column
void SaveAs(Stream s)
-
Saves the file
Examples
This example creates a .csv file with given values
import clr
clr.AddReferenceToFileAndPath(Session.GetAdapterPath("CSV"))
from IYOPROCsvAdapter import CSVDocument
import System
from System.IO import FileStream, FileMode
fs = FileStream("CSVSample.csv", FileMode.Create)
csv = CSVDocument()
#Header
csv.SetValue(1, 1, "Column A")
csv.SetValue(1, 2, "Column B")
csv.SetValue(1, 3, "Column C")
#Content
csv.SetValue(2, 1, "Hello")
csv.SetValue(2, 2, 3)
csv.SetValue(2, 3, 4.2)
csv.SaveAs(fs)
fs.Close()
This example creates and saves a .csv file with values of a data grid
import clr
clr.AddReferenceToFileAndPath(Session.GetAdapterPath("CSV"))
from IYOPROCsvAdapter import CSVDocument
import System
from System.IO import FileStream, FileMode
#Specify storage location and file name
localFile = "D:\\CSV Example Folder\\CSVSample.csv"
fs = FileStream(localFile, FileMode.Create)
csv = CSVDocument()
#Header (first row)
csv.SetValue(1, 1, "Column A")
csv.SetValue(1, 2, "Column B")
csv.SetValue(1, 3, "Column C")
#Content (from second row onwards)
i = 2
for entry in grid:
csv.SetValue(i, 1, entry["<key>"])
csv.SetValue(i, 2, entry["<key>"])
csv.SetValue(i, 3, entry["<key>"])
i = i + 1
csv.SaveAs(fs)
fs.Close()