Jump to content

Exporting data tables (cross or modified - calculated columns -) to excel/csv


Gustavo Pescador 2

Recommended Posts

Dear all,

Hope you can help me with this. I am trying to create a script with python where I can export modified tables (say in the data source I included some calculated colums) and/or cross tables. So far I am able to export the raw data (as I specify the input parameter as the data table) into an excel file, which I need to create beforehand otherwise the script does not work. When I change the input parameter to a visualization (cross table) I got errors of -- None Typeobject has no attribute exportdata -- among others as I change the code on the way to try new things. The initial code is below.

I have seen in the web that a lot of users have had the same complications with this and with them different codes which I have tried and none of the work, at least for me. I hope you can help me with this!

Thanks in advance!!

Gustavo

 

from Spotfire.Dxp.Data.Export import DataWriterTypeIdentifiers

from System.IO import File

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

filtering = Document.ActiveFilteringSelectionReference.GetSelection(table).AsIndexSet()

stream = File.OpenWrite("")

names = []

for col in table.Columns:

names.append(col.Name)

writer.Write(stream, table, filtering, names)

stream.Close()

Link to comment
Share on other sites

This is an example to export a Cross Table visualization to an excel file:

 

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)

Link to comment
Share on other sites

  • 8 months later...
  • 3 years 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...