Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I really do not understand why this is happening.
Duration (min., sec.)
2:24
4:20
4:20
4:20
3:54

Is outputted as:
Duration(min., sec.)
0.1
0.180555556
0.180555556
0.180555556
0.1625


Here is the code that does the conversion:
function convertXLStoCSV($infile, $outfile) // the function that converts the file
{
    $fileType = PHPExcel_IOFactory::identify($infile);
    $objReader = PHPExcel_IOFactory::createReader($fileType);
    $objReader->setReadDataOnly(true);
    $objPHPExcel = $objReader->load($infile);

    $writer = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV');
    $writer->setDelimiter(",");
    //$writer->setEnclosure("");
    //$writer->save("test123.csv");
    foreach ($objPHPExcel->getWorksheetIterator() as $workSheetIndex => $worksheet) {
        $objPHPExcel->setActiveSheetIndex($workSheetIndex);
        $writer->setSheetIndex($workSheetIndex);
        $writer->save('converted/' . $outfile ."_" . $worksheet->getTitle() . ".csv");
}

Thank you in advance.

What I have tried:

I did try to play with the Delimeter and Enclosure, but to no avail.
$writer->setDelimiter(",");
$writer->setEnclosure("");
Posted
Updated 5-Aug-17 2:05am

Times (and Dates) are stored in Excel as floating point numbers so you will need to convert them into their proper values. See Dates And Times In Excel[^].
 
Share this answer
 
Simple: Excel handle times in hours and minutes as a fraction of a day.
1 day is encoded as 1 in excel, you have just told Excel to format the value as hh:mm.
So 1 days is 24 hours, or 1440 minutes, or 8640 secondes.
So 0.1 day => 144 minutes => 2 hours and 24 minutes.

If you want to convert the fractions of days in Excel to hours and minutes in CSV, you need to convert the value yourself.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900