Jump to content

export cross table to excel - error opening in excel


Leo Naibat

Recommended Posts

Hi,

I used this scripts to export. the data was exported but when I am opening in excel gives me an error. Excel cannot open the file testexport.xlsx because the file format or file extension is not valid. If rename to testexport.xls and open the in excel gives an error fileformat and extension of testexport.xls dont math. if I open it shows the data. and all the records shows.

here is my script that I am using

import System

from System.IO import FileStream, FileMode

from Spotfire.Dxp.Application.Visuals import TablePlot

import clr

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

from System.Windows.Forms import SaveFileDialog

SaveFile = SaveFileDialog()

SaveFile.FileName = "ExportData.Xlsx"

SaveFile.Filter = "xlsx Format (*.xlsx)|*.xlsx|*.xls|*.xlsx" # "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.ExcelXlsxDataWriter)

stream = StreamWriter(saveFilename)

ExpData = myCrossTable.As[VisualContent]()

ExpData. ExportText(stream)

stream.Dispose()

 

Much appreciated for your help.

Leo

Link to comment
Share on other sites

Quick fixes to Excel Cannot Open the File.xlsx on Office

#1 Change the Excel File Extension Just copy and paste the file at any other location and rename it with a new name using .xls as extension.

So in the code above, try the modify the below line:

SaveFile.FileName = "ExportData.Xlsx"

TO

SaveFile.FileName = "ExportData.xls"

Link to comment
Share on other sites

Hi Rayees,

 

I copy the file to other location and rename it to xls. I also change my code extension to xls. 

 

when I am opening into excel it gives me this error. "The file you are trying to open,"ExportData.xls", is in different format that specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now.  When I open it shows the records then I need to save as again to xls or xlsx in order not to show the error warning. 

 

Do you know how and why this happening. Can you please try my code and fix it.

 

I attached my sample project.

 

Much appreciated.

 

Leo

 

 

Link to comment
Share on other sites

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