Jump to content

I had iPython code working in client for exporting visualization to excel, but same is not working in web browser. Can anyone suggest where is a mistake

Mukul Paranjpe

Recommended Posts

from System.IO import StreamWriter, Path, File

from Spotfire.Dxp.Application.Visuals import CrossTablePlot, TablePlot

from Spotfire.Dxp.Data.Export import DataWriterTypeIdentifiers

import tempfile

import os

#Common Language Runtime - manages execution of .NET programs

import clr

#Interop allows program to communicate with other MS office products,

# like Excel

clr.AddReferenceByName('Microsoft.Office.Interop.Excel, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c')

#clr.AddReferenceByName('Microsoft.Vbe.Interop, Version=, Culture=neutral, PublicKeyToken=71E9BCE111E9429C')

#clr.AddReferenceByName('Microsoft.Office.Excel, Version=, Culture=neutral, PublicKeyToken=71E9BCE111E9429C')

from Microsoft.Office.Interop import Excel

import csv

from datetime import datetime


from System.Drawing import Color, ColorTranslator


#translate colors to a format that Excel understands

def 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 text


#cast input variable as Spotfire TablePlot object to variable t

  t = table.As[TablePlot]()

  #export the data table


except Exception as e:




#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 session

ex = Excel.ApplicationClass()  

#make it visible (open)

ex.Visible = True

ex.DisplayAlerts = False  

#IMPORTANT: everything starts with the workbook object

workbook = ex.Workbooks.Open(tmp)

Link to comment
Share on other sites

  • 3 weeks later...

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

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