Juan Vaca Posted July 16, 2018 Share Posted July 16, 2018 One of my projectsis requesting to add an export data tableto excel sheet button on a page of a dashboard I'm creating. I found this code online but it doesn't export the data table to the excel it just pops the window to save a file in .xls . 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 More sharing options...
Pierre Nagellen Posted July 17, 2018 Share Posted July 17, 2018 Hi! Did you check that you defined crosstable as input to your script If yes, ty to replace the 2 last lines with this names = [col.Name for col in crosstable.Columns] filtering = Document.ActiveFilteringSelectionReference.GetSelection(table).AsIndexSet() writer.Write(stream, crosstable, filtering, names) stream.Dispose()That works for table but I did not test it for crosstables. Moreover, you have repetitions in your imports, you should cleanthem ;) Besides, System.Windows.Forms is not compatible with the web player. If you want something compatible with the web player while allowing the user to choose where to save the file, you will most likely need JavaScript. Link to comment Share on other sites More sharing options...
Charitha Amaraneni Posted September 16, 2019 Share Posted September 16, 2019 Hi Pito, Could you please brief me in a more detailed way about this as of how to get this Button functionality work even in Web Player. Thanks Link to comment Share on other sites More sharing options...
Pierre Nagellen Posted September 17, 2019 Share Posted September 17, 2019 Hi Ch3, "System.Windows.Forms" works only on windows environment. If the Web Player server is not under Windows, the library won't be usable, as the code will be executed on the server machine. Thate means, you have to specify the file location in another way. You could have a look there: https://spotfired.blogspot.com/2014/02/exporting-to-excel-web-player.html (or the other article mentionned at the end of the previous link). If you go for the first solution, the machine you want to export on should be available through the network. I hope this wil help :) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now