我想知道是否有人在这里尝试创建自动化服务以在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);
}
答案 0 :(得分:0)
要获取活动数据表引用,您应该使用
DataTable mytable = Application.Document.ActiveDataTableReference;
然后您可以在代码中进一步使用mytable
。