1

我想知道这里是否有人尝试创建自动化服务以在 Spotfire 自动化服务中将 DataTable 导出到 Xlsx?我一直在尝试创建一个,但我遇到了问题。如果有人能够做到这一点,您可以分享您的项目吗?

这是我到目前为止的代码,但在访问 DataSource 和 DataTable 时遇到了问题。

    protected override TaskExecutionStatus ExecuteCore(TaskExecutionContext context)
    {
        DataRowReader dataRowReader;
        ///Create a DataWriter
        DataWriter writer = context.Application.CreateDataWriter(DataWriterTypeIdentifiers.ExcelXlsDataWriter);
        ///<summary>
        ///Call the DataWriter Core from here or call a class that will do the relevant work
        ///<toDO>Need to find a way to access the current DataTable of the Open Analysis</toDo>
        ///</summary>
        Document doc = context.Application.Document;
        if(doc == null)
            return new TaskExecutionStatus(false, "NoAnalysisLoaded");

        DataManager data = doc.Context.GetService<DataManager>();

        DataTable table = data.Tables.Add(doc.ActiveDataTableReference, dataSource);


        string fileName = context.ExpandTags(this.filePath);
        FileStream fs = File.OpenWrite(fileName);
        //See how to properly impliment the writers
        writer.Write(fs, table, new IndexSet(table.RowCount, true), table.Columns.Names);

        fs.Close();
        data.Tables.Remove(table);
        return new TaskExecutionStatus(true);
    }
4

1 回答 1

0

要获取活动数据表引用,您应该使用

DataTable mytable = Application.Document.ActiveDataTableReference;

然后您可以mytable在代码中进一步使用。

于 2017-03-19T01:08:36.530 回答