Perspective email table data as xls

It took me a while to get this one to work, many forum searches later. To save someones pain, here is how to export table data as XLS and email it in perspective. If you unhash the download line and hash everything below you can download the file instead.

	table = self.parent.parent.getChild("Table Container").getChild("Table").props.data #Table you want to send/save
	excelstr = system.dataset.dataSetToExcel(True,[table])
	excelbytes = excelstr.encode("UTF8")
	fileName = 'test.xls'
	#system.perspective.download(fileName, excelbytes)
	smtp_server = 'Gmail' #Name of of the SMTP server in the gateway
	sender = "myemail@email.com"
	subject = "Here is the file you requested"
	body = "Hello, this is an email"
	recipients = ["myemail@email.com"]
	system.net.sendEmail(smtpProfile=smtp_server, fromAddr=sender, subject=subject, body=body, html=1, to=recipients, attachmentNames=[fileName], attachmentData=[excelbytes])
4 Likes

I was playing around and for some reason this way formats the table better and resizes the columns automatically.

   table = self.parent.parent.getChild("Table Container").getChild("Table").props.data
   fileName = 'test.xls'
   excelbytes = system.dataset.dataSetToHTML(1, table, "")
   #system.perspective.download(fileName, excelbytes)
   smtp_server = 'Gmail' #Name of of the SMTP server in the gateway
   sender = "myemail@email.com"
   subject = "Here is the file you requested"
   body = "Hello, this is an email"
   recipients = ["myemail@email.com"]
   system.net.sendEmail(smtpProfile=smtp_server, fromAddr=sender, subject=subject, body=body, html=1, to=recipients, attachmentNames=[fileName], attachmentData=[excelbytes])
4 Likes

I got this to work in vision without much problem, but how do I get this to work in a perceptive webpage?

Thanks!

My Man.

Thank you so much :relieved: