1

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:

enter image description here

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>";
    }

}
luator
  • 4,769
  • 3
  • 30
  • 51
Da_programmer
  • 177
  • 1
  • 15
  • Welcome to Stack Overflow. You can help us understanding your code more easily, if you remove everything, that is not related to your question (for example the for-loop which is doing nothing at all). Futher please include images directly in your Question, rather than linking them. The link may break in the future, which makes the question harder to understand. – luator Jun 08 '15 at 13:16
  • Okay i will try to do that. It's my first post so I coundn't include images. :( – Da_programmer Jun 08 '15 at 15:59
  • The value is an MS Excel timestamp value; what I don't understand is why the Writer isn't converting it to a string using your specified format mask – Mark Baker Jun 08 '15 at 16:54
  • @user3212296: Ah, I did not know, that new users cannot insert images. Never mind then. – luator Jun 08 '15 at 19:52

1 Answers1

0

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');
Da_programmer
  • 177
  • 1
  • 15