A classic ASP class that supports building, read and writing CSV, TSV (tab separated values) and HTML outputing, including a pretty print for HTML.
From: test.asp
set csv = new aspCsv
Add the header/titles for your structure:
' Add a header: setHeader(x, value)
csv.setHeader 0, "id"
csv.setHeader 1, "description"
csv.setHeader 2, "createdAt"
Add some data:
' Add the first data row: setValue(x, y, value)
csv.setValue 0, 0, 1
csv.setValue 1, 0, "obj 1"
csv.setValue 2, 0, date()
' Add a range of values at once: setRange(x, y, valuesArray)
csv.setRange 0, 2, Array(2, "obj 2", #11/25/2012#)
This will override the old informations
'Load a file:loadFromFile(path)
csv.loadFromFile("file_example_csv_10.csv")
Check if a column exist:
Check column existence: checkHeader(header)
If csv.checkHeader("description") Then Response.write("everything is okay ")
Get all values of a column:
'Get column's values: getColumnValues(header)
Dim cValues
cValues = csv.getColumnValues("description")
Get all values of a row:
'Get row's values: getRowValues(row)
Dim rValues
rValues = csv.getRowValues(0)
Get a cell's value:
'Get a cell's value: getCellValue(header, row)
Dim value
value = csv.getCellValue "description", 0
Output the data in string formatted values:
outputCSV = csv.toCSV()
outputTSV = csv.toTabSeparated()
outputHTML = csv.toHtmlTable()
csv.prettyPrintHTML = true
outputPrettyHTML = csv.toHtmlTable()
Or write it directly to a file:
' Write the output to a file: writeToFile(filePath, format)
csv.writeToFile("c:\mydata.csv", ASPcsv_CSV)
The format flags supported are:
ASPcsv_CSV = 1 ' CSV format
ASPcsv_TSV = 2 ' Tab separeted format
ASPcsv_HTML = 3 ' HTML table format