简体   繁体   中英

PHPExcel date formatting in strange numbers

I have made a script using PHPExcel to convert .xls files to .csv files. The .xls file has date formatting in it, and when converted to .csv the date fields has a high number increasing 1 for every day:

在此处输入图片说明

So how do I fix this? I want it to say it like this: 10/Jun or 15/Apr.

My code:

$count = 0;

foreach($html->find('section#content_main a') as $e) {

    echo "<h3>" . $e->href . "</h3>";
    $link = $e->href;
    echo "<p>" . $array[$count] . "</p>";
    $file = $array[$count] . ".xls";
    file_put_contents($file, fopen($link, 'r'));

    if(file_exists($array[$count] . ".csv") == 0){
        $fileType = PHPExcel_IOFactory::identify($file);
        $objReader = PHPExcel_IOFactory::createReader($fileType);
        $objReader->setReadDataOnly(false);


        for($i = 0; $i < (count($letters) * 2); $i++){

            if(i < count($letters)){

            }else{

            }

        }


        $objPHPExcel = $objReader->load($file);
        $objPHPExcel->getActiveSheet()->getStyle('B2')->getNumberFormat()
->setFormatCode('d-mmm');
        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV');
        $objWriter->save($array[$count] . ".csv");

        $count = $count + 1;
        echo "<p>File dosen't exist!</p>";
    }else{
        echo "<p>File do exist!</p>";
    }

}

Thanks for the support on my first post. I don't know what did the trick but i might think that it was this piece of code:

$objPHPExcel->getActiveSheet()->getStyle('B2:B6')->getNumberFormat()
->setFormatCode('d-mmm');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM