IronPython - Export Multiple .csv Files from 1 Data Table

Hi all,

I have a button control for a script that exports a data table as a .csv, code below. I would like to modify this so that instead of 1 .csv, the data table is separated into multiple csv files, as below.

Any advice would be most appreciated.

Thanks!

[Value]

1

1

1

2

2

3

3

4

 

.CSV1: Data rows where Value = 1 or Value = 2

.CSV2: Data rows where Value = 3 or Value = 4

 

Export Data Table as .CSV

import System
from System.IO import FileStream, FileMode
from Spotfire.Dxp.Application.Visuals import TablePlot
from  Spotfire.Dxp.Data.Export import DataWriterTypeIdentifiers
import clr
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import SaveFileDialog  
SaveFile = SaveFileDialog()   
SaveFile.Filter = "(*.csv)|*.csv|All Files (*.*)|*.*"
SaveFile.ShowDialog()
saveFilename = SaveFile.FileName
print "saveFilename=", saveFilename
stream = FileStream(saveFilename, FileMode.Create)
vizTable.As[TablePlot]().ExportData(DataWriterTypeIdentifiers.ExcelXlsxDataWriter, stream)
stream.Dispose()

(1) Answer

Login