Problem with ".csv" file

i using the gps sensor and try to save the data into the csv file format. Everything is working the only problem is i cant somehow save the value of GPS sensor in separate column in excel. The result get print in 1 line. i attached the pics below to understand the problem more clear. The following code i am using

String labels = "Latitude, Longitude, Time,  Date,"; //labels for fields in SD CSV file
String wFile = "WDATA"; //used as file name, need to follow 8.3 naming convention
void setup()
{
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
  Serial.begin(115200);
  ss.begin(GPSBaud);
   pinMode(10,OUTPUT);
   if (!SD.begin(chipSelect)) {
    // don't do anything more:
    return;
  }
  else {
    //Serial.println("card initialized.");
    bool file = false; //tracks when we found a file name we can use
    int count = 0; //used for naming the file
    while(!file){
      if(SD.exists(wFile + ".csv")) {
        count++; //up the count for naming the file
        wFile = "WDATA" + (String)count; //make a new name
      }
      else file = true; //we found a new name so we can exit loop
    } 
    File dataFile = SD.open((wFile + ".csv"), FILE_WRITE); //open file to write labels to CSV
    if (dataFile) {
      
      String labels = (F("Latitude, Longitude, Altitude, Speed, Distance"));
      
       dataFile.println(labels);
       dataFile.close(); //we are done with file so close it
       Serial.println(labels);
    }
    else { //if file doesn't open alert user
     Serial.begin(115200);
    Serial.println("error opening file..."); 
    Serial.println("");
    Serial.end();
    }
  }
  
  Serial.println("card initialized.");
}
void loop()
{
  int distance;
distance= ultrasonic();
   Serial.print(distance);
  printFloat(gps.location.lat(), gps.location.isValid(), 11, 6);
  printFloat(gps.location.lng(), gps.location.isValid(), 12, 6);
  printDateTime(gps.date, gps.time);
  printFloat(gps.altitude.meters(), gps.altitude.isValid(), 7, 2);
  printFloat(gps.speed.kmph(), gps.speed.isValid(), 6, 2);
  
   //---------------------------------------------------------------------------
   // The routine for writing data to SDcard: 
    File dataFile = SD.open((wFile +".csv"), FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile) {
    
    dataFile.print(gps.location.lat(),6);
    dataFile.print(",");
    dataFile.print(gps.location.lng(),6);
    dataFile.print(",");
    //dataFile.print(gps.date);
    //dataFile.print(",");    
    //dataFile.print(gps.time);
    //dataFile.print(",");
    dataFile.print(gps.altitude.meters());
    dataFile.print(",");
    dataFile.print(gps.speed.kmph());
    dataFile.print(",");
    dataFile.print(distance);
    dataFile.print("\n");
    dataFile.close();
  }

How are you importing the file into Excel ?

As a matter of interest, how exactly did you post your code as it has been split into one line sections ? Please delete the code from your original post and post it again in code tags as described in Read this before posting a programming question

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

Your data looks fine in the last image, are you loading it as a comma separated file in Excel?

Your posted code only needs ONE PAIR of code tags, not for each line.
You can go back and edit your post.
Good try!

Use Text to Columns under the Data tab
Screenshot from an ancient Excel version:

Your posted code only needs ONE PAIR of code tags, not for each line.

Actually, as originally posted there were no code tags, rather there were quote tags

I have seen this odd effect before and I am trying to track down what causes it so that it can be reported as a bug needing fixing

UKHeliBob. THANKS !

lastchancename:
Your data looks fine in the last image, are you loading it as a comma separated file in Excel?

Your posted code only needs ONE PAIR of code tags, not for each line.
You can go back and edit your post.
Good try!

sorry i am new here… i have change the code and put inside the quotes now. yes i am loading as comma separated file

Maybe attach the CSV file, and we can try/see what’s happening...
I assume the file looks ok in a plain text editor...?

lastchancename:
Maybe attach the CSV file, and we can try/see what’s happening...
I assume the file looks ok in a plain text editor...?

how can i upload csv file here ? and yes it looks ok in notepad

You can use the data import in excel (ad mentioned).

If you want to be able to simply see it in excel after double clicking the csv in windows explorer, there is a windows setting somewhere. Can't remember the details but it relates to the settings where you e.g. change decimal dot to comma etc. Do some research and you will find it.

how can i upload csv file here ?

Rename it to filename.txt and upload it

example.txt (43 Bytes)

here is the csv file.

WDATA8.txt (444 Bytes)

I downloaded the file, renamed it to test.csv then opened it with Excel by double clicking on it

No problems

excel capture.png

excel capture.png

UKHeliBob:
I downloaded the file, renamed it to test.csv then opened it with Excel by double clicking on it

No problems

excel capture.png

where should i click?

zaaddii:
where should i click?

On a link to a basic Excel tutorial.

zaaddii:
where should i click?

Double click on the .csv file on your PC and Excel should open and show your data in columns as in my screenshot

In google spreadsheet there is a button called split text into columns.
And this button is also under data menu in Excel see pic:

In google spreadsheet there is a button called split text into columns.
And this button is also under data menu in Excel see pic:

Whilst what you say is true it is totally unnecessary if the file is comma separated as Excel will import it into separate columns as standard

UKHeliBob:
Double click on the .csv file on your PC and Excel should open and show your data in columns as in my screenshot

Not necessarily; there is a windows setting that can screw it up. Seen it on other people's PC and my new work PC also suffers from it.

How to correctly display .csv files within Excel 2013? - Stack Overflow shows the solution.

UKHeliBob:
Whilst what you say is true it is totally unnecessary if the file is comma separated as Excel will import it into separate columns as standard

If the data is already loaded in exel, "split text into columns" is what you can do. Also useful if more data need to be added.
Just saying there are more roads to Rome.