Create CSV file with Excel compatibility

Topics: Developer Forum
Oct 9, 2014 at 3:46 PM
Edited Oct 9, 2014 at 3:47 PM
Hello, I'm using codeplex for a long time and it solves a lot of problems daily. I need to create a CSV file with Excel compatibility to be sent and processed.

Now I'm creating a CSV file like this:
    $objPHPExcel = new PHPExcel();
    // Set document properties
    $objPHPExcel->getProperties()->setCreator("xxxxxx")
                                 ->setLastModifiedBy("xxxxxx")
                                 ->setTitle("xxxxxx")
                                 ->setSubject("xxxxxx")
                                 ->setDescription("xxxxxx")
                                 ->setKeywords("xxxxxx")
                                 ->setCategory("xxxxxx");

    $objPHPExcel->setActiveSheetIndex(0);

   /* code to insert data into excel file */
   $i = 1;
    foreach ($smsFinales as $objSms) {
        // Por cada idioma se genera una fila
        //////////////////////////////////////////
        $activeSheet->SetCellValue("A$i", $objSms->getTlf());
        $activeSheet->setCellValue("B$i", $objSms->getTxt());
        $i++;
    }
    $objWriter = new PHPExcel_Writer_CSV($objPHPExcel);
    $objWriter->setExcelCompatibility(true);
    $objWriter->save("bulksms.csv");
My problem is that if I open this bulksms.csv it has the correct visual format (each field in a column) but if I go to File -> Save as -> the format showed is Unicode UTF-16 (.txt). It must be in CSV format. How can I do it?

I hope you understand my question (my english skills are not very good)

Thanks in advance!
Oct 10, 2014 at 3:05 PM
I know my question is quite weird, but I need to create a csv file with fields in different columns

I have noticed that If I set
 $objWriter->setExcelCompatibility(true); 
each field are set in different column but the file format is File -> Save as -> the format showed is Unicode UTF-16 (.txt) (is incorrect for me)

However, if I don't include this line of code
  $objWriter->setExcelCompatibility(true);
the file format is File -> Save as -> the format showed is csv (is correct for me)

I need to set every field in a different column and the file format must be csv.

Any Clue?

Thanks