cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jsdom
Frequent Visitor

Convert CSV Column data type to string

Hi,

 

I have successfully parse a json and converted it to a csv file and a text file (.txt). The problem is, there are two columns that are being converted as integer when i open the csv file in excel. 

 

In parse JSON, the types are already "string".

jsdom_3-1603195633897.png

 

 

 

As you can see on the image below, Seq 1 & Seq 2 are of type string

jsdom_0-1603195287819.png

But when i open the csv file in excel , those columns are being treated as integer (which is not OK. )

 

In here, the Seq 1 & Seq 2 are automatically right aligned which means they are treated as integer when i open the file in excel. Unlike Seq3, which is left aligned and is being treated as string.

jsdom_1-1603195469429.png

 

I tried to convert the column to String but i am not sure if i am doing this right. The flow runs, but i still have the same problem.

jsdom_2-1603195580931.png

 

Any help is much appreciated.

 

Kind regards,

 

jsdom

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Paulie78
Super User
Super User

You need to use the Excel tab trick as discussed in this post:

 

https://superuser.com/questions/318420/formatting-a-comma-delimited-csv-to-force-excel-to-interpret-...

 

I built a flow and tested it with data like yours and it works well:

 

ExcelToText.png

 

Excel interprets it correctly:

 

ExcelToText2.png

 

Note that the initialize variable step literally has a tab copied and pasted into it. So the code looks like this:

{
    "inputs": {
        "variables": [
            {
                "name": "charTab",
                "type": "string",
                "value": "\t"
            }
        ]
    }
}

 

Hope this helps.

View solution in original post

5 REPLIES 5
Pstork1
Dual Super User III
Dual Super User III

In the Create CSV action add double quotes around those fields that are being interpreted as numbers.  That way when you open the CSV in Excel they will be implicitly read as strings.  The problem is that the CSV doesn't include any type information.  It assumes the data type of each entry based on the entry itself.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
jsdom
Frequent Visitor

@Pstork1 

 

Thanks! But unfortunately, those columns have double quotes now in them. I also tried to put single quote in the beginning of create csv, but the single quote appeared too. I also tried putting and equal sign, and equal + single quote.. but still the same. 

 

jsdom_0-1603201058043.png

 

Kind regards,

 

 

 

Paulie78
Super User
Super User

You need to use the Excel tab trick as discussed in this post:

 

https://superuser.com/questions/318420/formatting-a-comma-delimited-csv-to-force-excel-to-interpret-...

 

I built a flow and tested it with data like yours and it works well:

 

ExcelToText.png

 

Excel interprets it correctly:

 

ExcelToText2.png

 

Note that the initialize variable step literally has a tab copied and pasted into it. So the code looks like this:

{
    "inputs": {
        "variables": [
            {
                "name": "charTab",
                "type": "string",
                "value": "\t"
            }
        ]
    }
}

 

Hope this helps.

View solution in original post

jsdom
Frequent Visitor

@Paulie78 

 

Thank you so much! That really helps. 

 

jsdom_0-1603203389164.png

 

Kind regards,

 

@jsdom No worries, glad you got it sorted.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Users online (1,814)