Mukul Paranjpe Posted September 4, 2022 Share Posted September 4, 2022 from System.IO import StreamWriter, Path, Filefrom Spotfire.Dxp.Application.Visuals import CrossTablePlot, TablePlotfrom Spotfire.Dxp.Data.Export import DataWriterTypeIdentifiersimport tempfileimport os#Common Language Runtime - manages execution of .NET programsimport clr#Interop allows program to communicate with other MS office products,# like Excelclr.AddReferenceByName('Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c')#clr.AddReferenceByName('Microsoft.Vbe.Interop, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C')#clr.AddReferenceByName('Microsoft.Office.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C')from Microsoft.Office.Interop import Excelimport csvfrom datetime import datetimeclr.AddReference('System.Drawing')from System.Drawing import Color, ColorTranslator #translate colors to a format that Excel understandsdef rgbForExcel(r, g, b): return ColorTranslator.ToOle(Color.FromArgb(r, g, b))tmp = os.path.join(tempfile.gettempdir(), str(table.Title) +".csv")#tmp = "C:/Users/abraks/Documents/DDO/whoopesh.csv"stream = StreamWriter(tmp)#export texttry: #cast input variable as Spotfire TablePlot object to variable t t = table.As[TablePlot]() #export the data table t.ExportText(stream)except Exception as e: print(e)finally: stream.Close()#write file to csv so Excel can open it (assuming default delimiter for Excel is comma)reader = list(csv.reader(open(tmp, "r"), delimiter='t'))with open(tmp,'wb') as outfile: writer = csv.writer(outfile, delimiter=',') writer.writerows(row for row in reader)#setup Excel sessionex = Excel.ApplicationClass() #make it visible (open)ex.Visible = Trueex.DisplayAlerts = False #IMPORTANT: everything starts with the workbook objectworkbook = ex.Workbooks.Open(tmp) Link to comment Share on other sites More sharing options...
Vivek Kumar 10 Posted September 21, 2022 Share Posted September 21, 2022 There is no issues with code, however what you are trying will not help you with webplayer.Reason is very simple, IronPython code runs at your local machine when you execute on your client, however same runs on Server when you run with webplayer. So, what ever file you are creating - they are getting populated and displayed on Webplayer Server rather than end user's machine.So far there are no clear approaches known to achieve what you are attempting, but there is a close alternative. Append a block of code to retrieve the session parameters (username/email id of user) and deliver the file to end users mail box directly. 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