Jump to content
  • How can I create a new empty data table through ironPython script?


    I have an IronPython script that reads data from data source and prints it in a visualization table. In some specific cases I wanted not to read the data from a data source, rather I wanted to create an empty table and display that table with a message.

    Please use below IP Script for creating empty rows containing template structure but no rows in it. Also please any share existing script you are using for complete solution to your issue . Hope this helps!

    import System
    import Spotfire.Dxp.Application
    from Spotfire.Dxp.Data import *
    from Spotfire.Dxp.Application.Visuals import VisualContent
    from System.Collections.Generic import HashSet
    from System.IO import FileStream, FileMode, File, MemoryStream, SeekOrigin, StreamWriter
    import System.String
    from Spotfire.Dxp.Data.Import import TextDataReaderSettings
    from Spotfire.Dxp.Data.Import import TextFileDataSource
    from Spotfire.Dxp.Data.Import import DataTableDataSource
    from System import DateTime
    
    def LoadCSV(dataTableName, stream):
        settings = TextDataReaderSettings()
        settings.Separator = ","
        settings.AddColumnNameRow(0)
        settings.ClearDataTypes(False)
        settings.SetDataType(0, DataType.Integer)
        settings.SetDataType(1, DataType.String)
        stream.Seek(0, SeekOrigin.Begin)
        fs = TextFileDataSource(stream, settings)
        if Document.Data.Tables.Contains(dataTableName):
            Document.Data.Tables[dataTableName].ReplaceData(fs)
        else:
            Document.Data.Tables.Add(dataTableName, fs)
    
    # Create new data table with a row for every month
    stream = MemoryStream()
    csvWriter = StreamWriter(stream)#, Encoding.UTF8)
    csvWriter.WriteLine("ID,Namern")
    
    csvWriter.Flush()
    LoadCSV("Aakash Sample", stream)
    
    # The original data table
    # Add Rows
    ds = DataTableDataSource(Document.Data.Tables["Aakash Sample"])
     

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...