Jump to content
Welcome to the new Spotfire community! Please see the sidebar announcement for more information on how to log in and get started! ×

IronPython export Cross table to Excel but corrupted data

Bill Koppelman

Recommended Posts

I am using the IronPython code from the solution here:https://community.spotfire.com/questions/exporting-data-tables-cross-or-modified-calculated-columns-excelcsv to export my cross table to excel. However, when I open the excel file, I get an error (pic attached) that says the file is corrupted or unsafe. When I click yes to open it anyways, the data is all there in working order.

Is there something wrong in the code that is causing this error

import System

from System.IO import FileStream, FileMode

from Spotfire.Dxp.Application.Visuals import TablePlot

from Spotfire.Dxp.Data.Export import DataWriterTypeIdentifiers

import clr



from System.Windows.Forms import SaveFileDialog

SaveFile = SaveFileDialog()

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


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]()


Link to comment
Share on other sites

  • 1 year later...
  • 7 months later...


I think it has to do with the line:

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

This writer is not referenced again, instead the StreamWriter is used to export the data.  I'm struggling with the same error and do not know the solution.

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