我想知道这里是否有人尝试创建自动化服务以在 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);
}