2014-06-15 66 views
1

我想知道是否有人在這裏嘗試創建一個自動化服務,以在Spotfire自動化服務中將數據表導出到Xlsx?我一直在嘗試創建一個,但我遇到了問題。如果有人能夠做到這一點,你可以分享你的項目嗎?Spotfire自動化Xlsx DataWriter

這是我迄今爲止的代碼,但在訪問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活動數據表中的參考。