Jump to content

How can I add a button and export the cross table data from a report to excel


vibin m

Recommended Posts

  • 11 months later...

You can create a Text Area, and insert an Action Control which executes an IronPython script. Here is a sample script to save a cross table to an Excel .xls file (with prompt):

 

import System

from System.IO import FileStream, FileMode

from Spotfire.Dxp.Application.Visuals import TablePlot

from Spotfire.Dxp.Data.Export import DataWriterTypeIdentifiers

import clr

clr.AddReference("System.Windows.Forms")

 

from System.Windows.Forms import SaveFileDialog

SaveFile = SaveFileDialog()

SaveFile.Filter = "Excel Workbook (*.xls)|*.xls"

SaveFile.ShowDialog()

saveFilename = SaveFile.FileName

 

from Spotfire.Dxp.Application.Visuals import VisualContent,TablePlotColumnSortMode

from Spotfire.Dxp.Data.Export import DataWriterTypeIdentifiers

from System.IO import File, StreamWriter

writer = Document.Data.CreateDataWriter(DataWriterTypeIdentifiers.ExcelXlsDataWriter)

stream = StreamWriter(saveFilename)

te = crossTable.As[VisualContent]()

te.ExportText(stream)This requires that you define "crossTable" as an input parameter which is defined as the cross table you want to export.

Link to comment
Share on other sites

  • 5 months later...
Thanks Sean.  I tried u[[{"fid":"112966","view_mode":"default","fields":{"format":"default","field_file_image_alt_text[und][0][value]":"","field_file_image_title_text[und][0][value]":""},"type":"media","attributes":{"height":"1038","width":"1483","class":"media-element file-default"}}]]sing this script but was unable to see the data.  Wondering what I am missing.
Link to comment
Share on other sites

Your input parameter is called Viz1, and not crossTable like required:

 

This requires that you define "crossTable" as an input parameter which is defined as the cross table you want to export.

 

And you modified the following line incorrectly:

 

te = crossTable.As[Viz1]()

 

 

 

If you did want to keep your input parameter named Viz1 then this would be how to modify the script:

 

te = Viz1.As[VisualContent]()

 

 

Link to comment
Share on other sites

And if I have 50 different visualizations (crosstables) that I would like to export to a common directory with the click of one action button.  Is that possible as well I looked at the automation services but it only offers crosstable exports as text files.
Link to comment
Share on other sites

  • 11 months later...
  • 1 year later...

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...