Jump to content

How to execute the "Export table" menu item programatically in C#

Georgi Koemdzhiev

Recommended Posts

Hello, I am trying to figure out if it's possible to programmatically call the "Export table" menu item that appears when the user right-clicks on a Table visualization onthe WebPlayer.

The reason I am trying to do that is I am trying to develop a CustomTool C# extension to download the data that is currently shown in a Map chart. To do that, the current implementation converts a Map chart to a Table so I can call its ExportData method. However, that method requires a FileStream which requires a path. If I use the current implementation the logic tries to save the resulting file on the WebPlayer's server and not stream it down to the user's browser.


So I am thinking if there is a way to execute the "Export table" context menu item that is already build-in to Spotfire WebPlayer from code. The method downloads the resulting Excell file to the user (i.e. normal browser download behaviour).



Current snippet of code in my CustomTool:

protected override void ExecuteCore(VisualContent map)




var doc = map.Context.GetAncestor();

AggregatedTransactionHandle transaction = doc.Transactions.BeginAggregatedTransaction();




var visual = map.Visual;

visual.TypeId = VisualTypeIdentifiers.Table;

var table = visual.As();


var dm = doc.Data.Markings.DefaultMarkingReference;



var pathWithEnv = @"%UserProfile%DesktopExportData.xls";

var filePath = Environment.ExpandEnvironmentVariables(pathWithEnv);


if (!Directory.Exists(filePath))





using (FileStream stream = File.Open(filePath, FileMode.Create))


table.ExportData(DataWriterTypeIdentifiers.ExcelXlsDataWriter, stream);






Link to comment
Share on other sites

It might not be possible to trigger the export table UI functionality. Have you looked into developing a CustomExportTool instead of a CustomTool This will give you the ability to download the file on to users machine.


You can refer to the HTMLPrintTool example in the SDK which has the above implementation.

Or one other approach is to provide a UNC path in the custom tool where the user has access to so that they can access the file once exported.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...