# toCSV is Downloading as a .txt file

**URL:** <https://forum.inductiveautomation.com/t/tocsv-is-downloading-as-a-txt-file/104307>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [March 27, 2025, 1:56pm UTC](https://forum.inductiveautomation.com/t/tocsv-is-downloading-as-a-txt-file/104307 "2025-03-27T13:56:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![cwkidd](https://avatars.discourse-cdn.com/v4/letter/c/35a633/32.png) [@cwkidd](https://forum.inductiveautomation.com/u/cwkidd)\
**Post date:** [March 27, 2025, 1:56pm UTC](https://forum.inductiveautomation.com/t/tocsv-is-downloading-as-a-txt-file/104307/1 "2025-03-27T13:56:31Z")

</div>

I know that I'm doing something incorrectly, as I'm not amazingly practiced with Python and with Perspective scripting, so I apologize if it's something really obvious. I'm running some tests for a download button on a table component. The button works, technically! However, it is downloading as a \*.txt file rather than a \*.csv. I figure I've done something in the script...but I can't really pinpoint where.

```python
def runAction(self, event):
	tableData = self.getSibling('TestTable')
	
	csv = system.dataset.toCSV(tableData.props.data)
	
	system.perspective.download('tableData', csv)

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 27, 2025, 1:58pm UTC](https://forum.inductiveautomation.com/t/tocsv-is-downloading-as-a-txt-file/104307/2 "2025-03-27T13:58:06Z")

</div>

Well, CSV **is** a text format, so autodetection will do that. Supply a content type to `system.perspective.download`.

---

<div class="post-metadata">

**Author:** ![kyvislabs](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kyvislabs/32/26325_2.png) [@kyvislabs](https://forum.inductiveautomation.com/u/kyvislabs)\
**Post date:** [March 27, 2025, 2:16pm UTC](https://forum.inductiveautomation.com/t/tocsv-is-downloading-as-a-txt-file/104307/3 "2025-03-27T14:16:25Z")

</div>

To add to Phil's response, here is the modification you need to make.

```python
system.perspective.download('tableData', csv, 'text/csv')

```

---

<div class="post-metadata">

**Author:** ![cwkidd](https://avatars.discourse-cdn.com/v4/letter/c/35a633/32.png) [@cwkidd](https://forum.inductiveautomation.com/u/cwkidd)\
**Post date:** [March 27, 2025, 7:54pm UTC](https://forum.inductiveautomation.com/t/tocsv-is-downloading-as-a-txt-file/104307/4 "2025-03-27T19:54:59Z")

</div>

Thank you! Another issue I'm having is that the t\_stamp isn't exporting correctly? Or it is, and I haven't formatted it correctly. It's just showing the time, but not the date itself, however the date is shown in the perspective table.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 27, 2025, 8:01pm UTC](https://forum.inductiveautomation.com/t/tocsv-is-downloading-as-a-txt-file/104307/5 "2025-03-27T20:01:28Z")

</div>

> [@cwkidd](#):
>
> It's just showing the time, but not the date itself

Did you open the CSV in Excel, or in a text editor? If not a text editor, use a text editor to see what was really exported.

---

<div class="post-metadata">

**Author:** ![cwkidd](https://avatars.discourse-cdn.com/v4/letter/c/35a633/32.png) [@cwkidd](https://forum.inductiveautomation.com/u/cwkidd)\
**Post date:** [March 27, 2025, 8:24pm UTC](https://forum.inductiveautomation.com/t/tocsv-is-downloading-as-a-txt-file/104307/6 "2025-03-27T20:24:31Z")

</div>

It was Excel. the text editor is showing the correct timestamp-- eg. "2024-03-03 00:00:00" instead of just "00:00:00"

---

<div class="post-metadata">

**Author:** ![cwkidd](https://avatars.discourse-cdn.com/v4/letter/c/35a633/32.png) [@cwkidd](https://forum.inductiveautomation.com/u/cwkidd)\
**Post date:** [March 28, 2025, 6:59pm UTC](https://forum.inductiveautomation.com/t/tocsv-is-downloading-as-a-txt-file/104307/7 "2025-03-28T18:59:12Z")

</div>

Any clue how to format the csv so it shows the actual tstamp? It's obviously being exported in some way, because it's showing it when I view it in Notepad. Just not Excel.

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [March 28, 2025, 7:19pm UTC](https://forum.inductiveautomation.com/t/tocsv-is-downloading-as-a-txt-file/104307/8 "2025-03-28T19:19:24Z")

</div>

That's an Excel issue. When opening most CSVs in Excel, timestamp isn't reliably shown.  
If this is going to always be opened in Excel, then use the system.dataset.toExcel function to get a reliable spreadsheet.

Otherwise, you will need to open the file in Excel and then manually format the column as a DateTime. Just know that column formatting isn't part of a CSV, so that won't be saved with the file.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 28, 2025, 7:25pm UTC](https://forum.inductiveautomation.com/t/tocsv-is-downloading-as-a-txt-file/104307/9 "2025-03-28T19:25:58Z")

</div>

Consider converting to Excel directly, instead of to CSV. That CSV opens in Excel by default is utter bogus, IMNSHO.
