Problem to create a Excell with database information

Topics: Developer Forum, Project Management Forum, User Forum
Jun 20, 2012 at 5:30 PM

Hi to all

I need to save some information fron de Database to excel, I checked this file 01simple-download-xlsx.php in order to do that  but when I add the code to get the information into the file and "run" it I got a error messege from excel that said "Excel cannot open the file 01simple.xlsx because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension marches the format of the file.

BTW, I tested the code to get the information from the database in other file and eorked excelent, and I tested the 01simple-download-xlsx.php alone and worked excellent.

Can someone give a help about what can be the problem.

Jun 20, 2012 at 5:59 PM

You have probably echoed some output to the browser in addition to the file output. Save the file, then open it in a text editor: look for whitespace at the beginning or end, or any obvious error messages (e.g. headers already sent)

Jun 20, 2012 at 6:10 PM

Hey MarkBaker

Thank you very much... You were right... in my code I had some echo, I removed them and test it and work it fine :) thank you....

How can add style the title in excell, I mean that the title will be in bold and color blue for example...

Beste regards,

Jun 20, 2012 at 9:09 PM

Hi.... I don´t know why... I just inserted this code and I got the same error messege

$porcentaje = 0;
for ($y=0; $y<$x; $y++)
    $x = $respuestas[$y][2]*100;
    $porcentaje = $x/$votos_totales;
    $respuestas[$y][3] = $porcentaje;

What can be de problem ?

Best regards..

Jun 21, 2012 at 10:58 PM

Hi .... sorry... but.... someone has and idea about this problems

Thank you for your help

Jun 21, 2012 at 11:14 PM

Do the same as before, open the file in a text editor and look for error messages, particularly "index doesn't exist" warnings

Always try that first before you even post here

Jun 22, 2012 at 6:48 PM

Hi MarkBaker

Thank you for you help. I checked it and I saw another problem in the code but I fixed it and worked fine

but the way I need to add a data in a cell and I checked in a example that you have ( in the line 347 said

$objPHPExcel->getActiveSheet()->setCellValue('A3', $sLloremIpsum);

I did the same line in my file: $objPHPExcel->setActiveSheetIndex(0)->setCellValue('H4', $row['question']); ..... but when the excell file is opened the cell H4 is empty, I checeked the variable $row['question'] and it isn´t empty

What can be the problem

Jun 22, 2012 at 10:00 PM

Without trying to second guess, the most obvious explanation is that $row['question'] is empty

Jun 22, 2012 at 10:15 PM

Hi MarkBaker , Thank you very much for your answer

You know.... is very strange becuase I use an variable that is used to share some information in the code, actually a add this variable, see ... $objPHPExcel->getActiveSheet(0)->setCellValue('F11', $encuesta_pregunta); and I can´t see anything, I´m sure that this variable is not empty because I saw it in de debbuger.

Any Idea abut that.... sorry to bother you

Jun 22, 2012 at 11:10 PM

Well the single line of code that you quote should set cell F11 to the value of $encuesta_pregunta. Could there be anything you're doing in other lines of code that changes it?