I’m using PHPExcel to export data from a MYSQL database and import it into an excel file.
I’ve got a database that looks like this (this is also what my excel file currently looks like when I generate it using PHPExcel):
======================================================
| Question | Answer |
=========+===========+===============================|
| Do you listen to music? | YES |
|----------------------------------------------------|
| Who is your favorite music artists? | Justin Beiber|
|----------------------------------------------------|
| <p> Select an Answer<p> | |
|----------------------------------------------------|
|Are you a Male or female | M |
|----------------------------------------------------|
I want my excel file to look like this:
======================================================
| Question | Answer |
=========+===========+===============================|
| Do you listen to music? | YES |
|----------------------------------------------------|
| Who is your favorite music artists? | Justin Beiber|
|----------------------------------------------------|
|Are you a Male or female | M |
|----------------------------------------------------|
I’m using this code:
$objPHPExcel = new PHPExcel();
$col = 1;
while($row_data = mysql_fetch_assoc($result)) {
$row = 1;
if ($col == 1) {
$row_headings = array_keys($row_data);
foreach($row_headings as $value) {
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value);
$row++;
}
$row = 1;
$col++;
}
foreach($row_data as $value) {
if (!strstr('<p>', $value)){
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value);
$row++;
}
}
$col++;
}
One option would be to exclude the
<p> Select an Answer<p>when doing a SQL query you would SELECT your columns and rows then from your selection you couldDELETE WHERE question = "<p> Select an Answer<p> "Or if column
Anwservalue isnullor""whenQuestionvalue is<p> Select an Answer<p>, then you can could also say:In example:
Or you could simply delete rows that contain
<p> Select an Answer<p>unless you need them.