# Problem with export the data from dataset format To CSV (UTF-8)

**URL:** <https://forum.inductiveautomation.com/t/problem-with-export-the-data-from-dataset-format-to-csv-utf-8/90120>\
**Category:** Ignition\
**Tags:** python, scripting, ignition81, perspective\
**Created:** [May 8, 2024, 6:13pm UTC](https://forum.inductiveautomation.com/t/problem-with-export-the-data-from-dataset-format-to-csv-utf-8/90120 "2024-05-08T18:13:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kaviya\_D](https://avatars.discourse-cdn.com/v4/letter/k/958977/32.png) [@Kaviya\_D](https://forum.inductiveautomation.com/u/Kaviya_D)\
**Post date:** [May 8, 2024, 6:13pm UTC](https://forum.inductiveautomation.com/t/problem-with-export-the-data-from-dataset-format-to-csv-utf-8/90120/1 "2024-05-08T18:13:59Z")

</div>

Hello Everyone,

Any one can help me to solve this issue...?

I have One Perspective View where I can enter all the details to create the work order. Once I create the Order, the data will be saved into the database. Each work order data I have, the Column Name is like Remarks which is having the description about the work order purpose. That description is sometimes entered with chinese characters.

Another view, I have the Table Component, which is used to view the list of work orders that is created by the users. On the same page, I have the Export button to export the data to CSV format. That is also working quite well.

But my problem is if I have the chinese description of my work order data, which is showing as special characters, when I open the CSV file using EXCEL.

Now I want to export the CSV file with UTF-8 format. Here I mention the Script which I used to export the data to CSV for your reference.

Here myData is my Table Data

```python
ds = system.dataset.toDataSet( header , myData )

dataset = ds

data = system.dataset.toCSV(dataset, 1, 0, 0)

Filename = 'Exportdata.csv'

system.perspective.download(Filename, data)

```

If I open the downloaded file using excel, chinese characters showing as special characters.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/6/d6bd49a325e8ab5e9e171e17b55a48076260c099.png)  
this is how its showing in excel.  
but in my data set those values are in unicode format

> for example : **\u8c22\u8c22** - this is how my data in my dataset.  
> It has to shown as **谢谢** in my excel.

but its not showing as it is. What to do in this situation. How can I export the CSV with utf-8 format.

Also I tried with below condition

```python
system.perspective.download(Filename, data,"charset=utf-8")

```

But Couldn't.

Kindly help me to solve this.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 8, 2024, 6:40pm UTC](https://forum.inductiveautomation.com/t/problem-with-export-the-data-from-dataset-format-to-csv-utf-8/90120/2 "2024-05-08T18:40:22Z")

</div>

In the simplest possible case, this worked as expected for me:

```python
def runAction(self, event):
	ds = system.dataset.toDataSet(["column"], [[u"谢谢"]])
	csv = system.dataset.toCSV(ds)
	
	system.perspective.download("test.csv", csv)	

```

This generated this file:  
[test.csv](https://forum.inductiveautomation.com/uploads/short-url/dCMSA8VcFEqSKblEEAEV4tCSe10.csv) (18 Bytes)

Can you confirm the data is represented in the dataset, and in the string CSV output, in the format you expect? E.g. via `system.perspective.print`?

> [@Kaviya\_D](#):
>
> system.perspective.download(Filename, data,"charset=utf-8")

I wouldn't expect this to make the difference, but you should use `text/csv; charset=utf-8` as your content type value.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 8, 2024, 6:54pm UTC](https://forum.inductiveautomation.com/t/problem-with-export-the-data-from-dataset-format-to-csv-utf-8/90120/3 "2024-05-08T18:54:48Z")

</div>

Welcome to the forum. Please see [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831).

---

<div class="post-metadata">

**Author:** ![Kaviya\_D](https://avatars.discourse-cdn.com/v4/letter/k/958977/32.png) [@Kaviya\_D](https://forum.inductiveautomation.com/u/Kaviya_D)\
**Post date:** [May 8, 2024, 8:52pm UTC](https://forum.inductiveautomation.com/t/problem-with-export-the-data-from-dataset-format-to-csv-utf-8/90120/4 "2024-05-08T20:52:49Z")

</div>

> [@paul-griffith](#):
>
> I wouldn't expect this to make the difference, but you should use `text/csv; charset=utf-8` as your content type value.

I will try this and let you know soon, and will share the dataset data here by using print function for your better understanding about my issue.

---

<div class="post-metadata">

**Author:** ![Kaviya\_D](https://avatars.discourse-cdn.com/v4/letter/k/958977/32.png) [@Kaviya\_D](https://forum.inductiveautomation.com/u/Kaviya_D)\
**Post date:** [May 9, 2024, 3:10pm UTC](https://forum.inductiveautomation.com/t/problem-with-export-the-data-from-dataset-format-to-csv-utf-8/90120/5 "2024-05-09T15:10:51Z")

</div>

@paul-griffith  
FYR

> header = ["SNO","MACHINE\_ID","Order\_No","Quantity","Remarks","Date","Created By"]

> myData = [[1, 'MC01','KJ1121',10.0, u'\u8c22\u8c22', '09 May 2024', 'KAVIYA'],[2, 'MC01','KJ1122',10.0, 'TEST1', '09 May 2024', 'KAVIYA'],[3, 'MC01','KJ1123',10.0, 'TEST2', '09 May 2024', 'KAVIYA'],[4, 'MC01','KJ1124',10.0, 'TEST3', '09 May 2024', 'KAVIYA'],[5, 'MC01','KJ1125',10.0, 'TEST4', '09 May 2024', 'KAVIYA'],[6, 'MC01','KJ1126',10.0, 'TEST5', '09 May 2024', 'KAVIYA']]

The Above data needs to export as CSV. So I tried the Below mentioned Script.

> [@Kaviya\_D](#):
>
> ```python
> ds = system.dataset.toDataSet( header , myData )
> 
> dataset = ds
> 
> data = system.dataset.toCSV(dataset, 1, 0, 0)
> 
> Filename = 'Exportdata.csv'
> 
> system.perspective.download(Filename, data)
> 
> ```

If you see myData , the Index 0 is

> [1, 'MC01','KJ1121',10.0, u'\u8c22\u8c22', '09 May 2024', 'KAVIYA']

this data created with chinese description so that the data stored as unicode format

> u'\u8c22\u8c22'

But remaining orders are created with english description like Test1,Test2, Test3 like that.

After Conversion the 1st row data Remarks is showing special Characters which I mentioned previously.

Also I tried what you suggested in your reply

> [@paul-griffith](#):
>
> you should use `text/csv; charset=utf-8` as your content type value.

But no difference.

I hope now you have a clear idea about my issue.

Can you help me to solve this.?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 9, 2024, 3:33pm UTC](https://forum.inductiveautomation.com/t/problem-with-export-the-data-from-dataset-format-to-csv-utf-8/90120/6 "2024-05-09T15:33:03Z")

</div>

Again, please see [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831). Don't post code as " or `>` quotations.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 9, 2024, 3:46pm UTC](https://forum.inductiveautomation.com/t/problem-with-export-the-data-from-dataset-format-to-csv-utf-8/90120/7 "2024-05-09T15:46:45Z")

</div>

I think the problem here is Excel, not Ignition. With your script, I get the actual data you're expecting if I open the file in a text editor:

 ![Screenshot 2024-05-09 at 8.44.24 AM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/d/8de4a1d89bed4a5996f2d4ada6a1b5acefb2f8f3.png)

Consider writing out the file data with a leading 'byte order mark', to make it UTF-8 with BOM, which I suspect Excel is expecting:  
`system.perspective.download(Filename, u'\uFEFF' + data)`

> **[Byte order mark](https://en.wikipedia.org/wiki/Byte_order_mark)**
>
> The byte-order mark (BOM) is a particular usage of the special Unicode character code, .mw-parser-output .monospaced{font-family:monospace,monospace}U+FEFF ZERO WIDTH NO-BREAK SPACE, whose appearance as a magic number at the start of a text stream can signal several things to a program reading the text:
> BOM use is optional. Its presence interferes with the use of UTF-8 by software that does not expect non-ASCII bytes at the start of a file but that could otherwise handle the text stream.
> Uni...

---

<div class="post-metadata">

**Author:** ![Kaviya\_D](https://avatars.discourse-cdn.com/v4/letter/k/958977/32.png) [@Kaviya\_D](https://forum.inductiveautomation.com/u/Kaviya_D)\
**Post date:** [May 10, 2024, 11:13am UTC](https://forum.inductiveautomation.com/t/problem-with-export-the-data-from-dataset-format-to-csv-utf-8/90120/9 "2024-05-10T11:13:34Z")

</div>

It is working fine now.  
Thank you very much.
