There is a more straight forward method to import data from text/csv into Excel (2017):
- Open a blank book in Excel and click in import data from text/csv.
- Select the file.
- The assistant will show a preview of the data, but if you are importing from a csv with decimal / scientific numbers all will be recognized as text.
- Before importing, click on edit, you will see an Excel spreadsheet with a preview of your data.
- If you click on the advanced editor button, a new window with the query Excel does will appear.
You will see something like:
let
Origin = Csv.Document(File.Contents("C:\Users\JoseEnriqueP\Downloads\evaluation_output.txt"),[Delimiter=",", Columns=8, Encoding=1252, QuoteStyle=QuoteStyle.None]),
#"Updated type" = Table.TransformColumnTypes(Origin,{{"Column1", Int64.Type}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}, {"Column6", type text}})
in
#"Updated type"
Then, you can write down directly the types for each column:
- Text: type text
- Integers: Int64.Type
- Decimals: Double.Type
The import code would be as follows:
let
Origin = Csv.Document(File.Contents("C:\Users\JoseEnriqueP\Downloads\evaluation_output.txt"),[Delimiter=",", Columns=8, Encoding=1252, QuoteStyle=QuoteStyle.None]),
#"Updated type" = Table.TransformColumnTypes(Origin,{{"Column1", Int64.Type}, {"Column2", Int64.Type}, {"Column3", Int64.Type}, {"Column4", type text}, {"Column5", Double.Type}, {"Column6", Double.Type}})
in
#"Updated type"
By doing this, you will get directly your data into Excel.