我已经构建了一个C# CustomTool ,该C#将 MapChart 中的选定数据导出为xls(excel)格式。当我导出带有“嵌入分析”数据的分析文件的数据时,该扩展名可以正常工作。但是,当我尝试从使用远程数据的分析(即SQL Server)中导出所选数据时,它会填充所有数据表列名,但不会添加任何数据行。即使我已经在MapChart上选择了数据,也是如此。我不确定我可能会错过什么。
这是我的MapChart自定义工具代码:
public class VisualisationRightClickDownload : CustomTool<MapChart>
{
protected override bool GetSupportsPromptingCore() => true;
protected override IEnumerable<object> ExecuteAndPromptCore(MapChart context)
{
this.ExecuteCore(context);
yield break;
}
protected override bool IsEnabledCore(MapChart context) => true;
protected override void ExecuteCore(MapChart context)
{
var doc = context.Context.GetAncestor<Document>();
var dt = context.Data.DataTableReference;
var filtering = doc.ActiveMarkingSelectionReference.GetSelection(doc.ActiveDataTableReference).AsIndexSet();
var dm = context.GetService<DataManager>();
var writer = dm.CreateDataWriter(DataWriterTypeIdentifiers.ExcelXlsDataWriter);
var pathWithEnv = @"%UserProfile%\Desktop\SpotfireExport.xls";
var filePath = Environment.ExpandEnvironmentVariables(pathWithEnv);
Stream = stream = File.OpenWrite(filePath);
var names = new List<string>();
foreach (var col in dt.Columns)
{
names.Add(col.Name);
}
writer.Write(stream, dt, filtering, names);
stream.Flush();
stream.Dispose();
}
}
这是我的自定义工具注册代码:
public sealed class CustomAddIn : AddIn
{
protected override void RegisterTools(ToolRegistrar registrar)
{
CustomMenuGroup menuGroup = new CustomMenuGroup("Georgi Downlaod");
registrar.Register(new VisualisationRightClickDownload("Download viz data"), menuGroup);
}
}