# Perspective email table data as xls

**URL:** <https://forum.inductiveautomation.com/t/perspective-email-table-data-as-xls/28597>\
**Category:** Ignition\
**Created:** [September 26, 2019, 6:52pm UTC](https://forum.inductiveautomation.com/t/perspective-email-table-data-as-xls/28597 "2019-09-26T18:52:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigb](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@craigb](https://forum.inductiveautomation.com/u/craigb)\
**Post date:** [September 26, 2019, 6:52pm UTC](https://forum.inductiveautomation.com/t/perspective-email-table-data-as-xls/28597/1 "2019-09-26T18:52:04Z")

</div>

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.

```auto
	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])

```

---

<div class="post-metadata">

**Author:** ![craigb](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@craigb](https://forum.inductiveautomation.com/u/craigb)\
**Post date:** [September 26, 2019, 7:30pm UTC](https://forum.inductiveautomation.com/t/perspective-email-table-data-as-xls/28597/2 "2019-09-26T19:30:42Z")

</div>

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

```auto
   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])

```

---

<div class="post-metadata">

**Author:** ![shawn.waltz](https://avatars.discourse-cdn.com/v4/letter/s/e9a140/32.png) [@shawn.waltz](https://forum.inductiveautomation.com/u/shawn.waltz)\
**Post date:** [March 31, 2020, 3:56pm UTC](https://forum.inductiveautomation.com/t/perspective-email-table-data-as-xls/28597/3 "2020-03-31T15:56:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![larry.thigpen](https://avatars.discourse-cdn.com/v4/letter/l/58f4c7/32.png) [@larry.thigpen](https://forum.inductiveautomation.com/u/larry.thigpen)\
**Post date:** [June 1, 2020, 3:31pm UTC](https://forum.inductiveautomation.com/t/perspective-email-table-data-as-xls/28597/4 "2020-06-01T15:31:05Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![mblystone](https://avatars.discourse-cdn.com/v4/letter/m/9de053/32.png) [@mblystone](https://forum.inductiveautomation.com/u/mblystone)\
**Post date:** [August 27, 2021, 2:28pm UTC](https://forum.inductiveautomation.com/t/perspective-email-table-data-as-xls/28597/5 "2021-08-27T14:28:42Z")

</div>

My Man.

Thank you so much 😌
