Jump to content

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

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

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

Hello,

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