Mumble
Mumble

Reputation: 13

Spotfire Automation Xlsx DataWriter

I was wondering if anybody here attempted creating an Automation Service to Export a DataTable to Xlsx in Spotfire Automation Services? I have been trying to create one but I am having issues. If anybody has been able to do this can you please share your project?

THis is the code I have thus far but having issues with Accessing the DataSource and 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);
    }

Upvotes: 1

Views: 549

Answers (1)

sayTibco
sayTibco

Reputation: 166

To get the active data table reference you should use

DataTable mytable = Application.Document.ActiveDataTableReference;

and then you can use mytable further in the code.

Upvotes: 0

Related Questions