spotfire ironpython:将新行附加到数据-table

spotfire ironpython : Append new row to a data-table

我有一个 csv 字符串输入
string_in="country,100,color"
任何人都可以建议我如何使用 spotfire 中的 ironpython 脚本将此输入 (string_in) 附加到已经存在的
数据表可视化。
谢谢。

您需要引入一些不同的函数来通过脚本实现这一点。下面是我的脚本,但总的来说,您要做的是将输入设置为数据源,然后将该数据源中的行添加到现有数据源中。我从 TIBCO 的 this spotfire 教程中借用了大量内容,并根据需要对其进行了修改,以使我们达到您想要的效果。因此,您可能会删除一些多余的导入。

我使用 datTab 作为脚本的输入参数作为数据 table 我们要将行添加到其中。

from Spotfire.Dxp.Data import AddRowsSettings
import System
from System import DateTime
from System.IO import StringReader, StreamReader, StreamWriter, MemoryStream, SeekOrigin
from Spotfire.Dxp.Data import DataType, DataTableSaveSettings
from Spotfire.Dxp.Data.Import import TextFileDataSource, TextDataReaderSettings

#First we need to create your data with some columns. 
#Here I have a comma separated miniature table built up with 
#a commented option for your variable itself. \r\n used for newline
textData = "name,values,category\r\ncountry,100,color\r\n" 
#textData = "col1,col2,col3\r\n" + string_in + "\r\n"

#Memory Stream stuff. Simply just writing our variable 
#into a place we can access to make a data source
stream = MemoryStream()
writer = StreamWriter(stream)
writer.Write(textData)
writer.Flush()
stream.Seek(0, SeekOrigin.Begin)

#you need settings to tell the system what stuff you're importing.
#here we define it is comma separated and what data types our columns are.
readerSettings = TextDataReaderSettings()
readerSettings.Separator = ","
readerSettings.AddColumnNameRow(0)
readerSettings.SetDataType(0, DataType.String)
readerSettings.SetDataType(1, DataType.Integer)
readerSettings.SetDataType(2, DataType.String)
textDataSource = TextFileDataSource(stream,readerSettings)

#We create some settings here automatically having the system match
#column names for us between the data table and our data source.
settings = AddRowsSettings(datTab,textDataSource)
#And finally we add the rows from our datasource with our settings.
datTab.AddRows(textDataSource,settings)

您当然可以使用更长的输入变量使其变得更复杂,遍历事物以添加多行等。您也可以使用 URL 到文件而不是内存流来遵循相同的过程东西。取决于您的输入类型。

如果您有任何问题,请告诉我。我试图评论重要部分,但如果需要,可以对特定功能进行进一步解释。

编辑:在我添加了几次不同的记录后,请看下面的截图