Exportation into xls File Bug Code

Fermé
garrix_du77 Messages postés 52 Date d'inscription samedi 21 mai 2016 Statut Membre Dernière intervention 4 janvier 2024 - 30 août 2018 à 00:42
jordane45 Messages postés 38152 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 3 mai 2024 - 30 août 2018 à 01:25
Bonsoir les amis , merci Bien d'abord d'être ici et d'essayer de me donner un coup de pousse !
alors mon problème c'est dans l'exportation de ma requête dans un fichier XLS .
bon le code fonctionne parfaitement sauf que mon soucis c'est quand je ouvre mon fichier je trouve le code HTML dans mon ficher XLS en dessous de mes données voici ce que sa donne :


et voilà mon code PHP :

<?php
/*******EDIT LINES 3-8*******/
ini_set("display_errors",0);error_reporting(0);
$DB_Server = "localhost"; //MySQL Server
$DB_Username = "root"; //MySQL Username
$DB_Password = ""; //MySQL Password
$DB_DBName = "csv_db"; //MySQL Database Name
$DB_TBLName = "produit"; //MySQL Table Name
$filename = "excelfilename"; //File Name
/*******YOU DO NOT NEED TO EDIT ANYTHING BELOW THIS LINE*******/
//create MySQL connection
$host = "localhost"; // MySQL host name eg. localhost
$user = "root"; // MySQL user. eg. root ( if your on local server)
$password = ""; // MySQL user password (if password is not set for your root user then keep it empty )
$database = "csv_db"; // MySQL Database name

// Connect to MySQL Database
$con = new mysqli($host, $user, $password, $database);

// Check connection
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);
}

if (isset($_POST['requete']))
{
if((!empty($_POST['ap_Model']) ) && (empty($_POST['ap_sw_version']))&& (empty($_POST['sta_sw_version'])) && (empty($_POST['location_name']))&& (empty($_POST['configuration_transfert_type_0']))&& (empty($_POST['configuration_transfert_type_1']))&& (empty($_POST['configuration_protocol_0']))&& (empty($_POST['configuration_protocol_1'])))
{
$selected_val = $_POST['ap_Model'];
foreach ($selected_val as $select) {
$sql = "Select * from $DB_TBLName produit where ( ap_model='$select' )";
$Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password) or die("Couldn't connect to MySQL:<br>" . mysql_error() . "<br>" . mysql_errno());
//select database
$Db = @mysql_select_db($DB_DBName, $Connect) or die("Couldn't select database:<br>" . mysql_error(). "<br>" . mysql_errno());
//execute query
$result = @mysql_query($sql,$Connect) or die("Couldn't execute query:<br>" . mysql_error(). "<br>" . mysql_errno());
$file_ending = "xls";
//header info for browser
header("Content-Type: application/xls");
header("Content-Disposition: attachment; filename=$filename.xls");
header("Pragma: no-cache");
header("Expires: 0");
/*******Start of Formatting for Excel*******/
//define separator (defines columns in excel & tabs in word)
$sep = "\t"; //tabbed character
//start of printing column names as names of MySQL fields
for ($i = 0; $i < mysql_num_fields($result); $i++) {
echo mysql_field_name($result,$i) . "\t";
}
print("\n");
//end of printing column names
//start while loop to get data
while($row = mysql_fetch_row($result))
{
$schema_insert = "_";
for($j=0; $j<mysql_num_fields($result);$j++)
{
if(!isset($row[$j]))
$schema_insert .= "NULL".$sep;
elseif ($row[$j] != "")
$schema_insert .= "$row[$j]".$sep;
else
$schema_insert .= "".$sep;
}
$schema_insert = str_replace($sep."$", "", $schema_insert);
$schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert);
$schema_insert .= "\t";
print(trim($schema_insert));
print "\n";
}
}

// requete
}
}
if(isset($_POST['submit']))
{
if((!empty($_POST['ap_Model']) ) && (empty($_POST['ap_sw_version']))&& (empty($_POST['sta_sw_version'])) && (empty($_POST['location_name'])))
{
$selected_val = $_POST['ap_Model']; // Storing Selected Value In Variable
// Displaying Selected Value

$compteur = 0;
foreach ($selected_val as $select )
{
$sql1 = "Select * from produit where (ap_model ='$select')"; $res1 = mysqli_query($con, $sql1) or die ("Erreur dans la requete ".mysqli_error($con));if ($compteur <1){if (mysqli_num_rows($res1)>0)$produit = '<table border ="1"><tr> <th>wlan_test_run_date</th>
<th>wlan_test_run_time</th>
<th>tester_company</th>
<th>tester_operator_name</th>
<th>location_site</th>
<th> location_description </th>
<th> location_name</th>
<th> location_distance </th>
<th> location_floor </th>
<th> location_thin_wall </th>
<th> location_thick_wall </th>
<th> location_pathloss </th>
<th> location_conducted_attenuation</th>
<th> wlan_test_run_info </th>
<th> ap_manufacturer </th>
<th> ap_model</th>
<th> ap_serial_number </th>
<th> ap_hw_version </th>
<th> ap_sw_version </th>
<th> ap_wifi_driver_version </th>

<th> ap_certification </th>
<th> ap_calibration_version </th>
<th> sta_manufacturer </th>
<th> sta_model </th>
<th> sta_serial_number </th>
<th> sta_hw_version </th>
<th> sta_sw_version </th>
<th> sta_wifi_driver_version </th>





<th> configuration_band </th>
<th> configuration_modulation </th>
<th> configuration_bandwidth</th>
<th> configuration_channel </th>
<th>
configuration_transfert_type</th>
<th> configuration_radiated_mode </th>
<th> configuration_conducted_attenuation </th>
<th> configuration_security</th>
<th> configuration_protocol</th>
<th> configuration_anglev </th>
<th> configuration_angleh </th>
<th>measurement_throughput </th>
<th>measurement_sta_rssi</th>
<th> measurement_rx_rate</th>
<th> measurement_tx_rate</th>
<th> measurement_rx_stream</th>
<th>measurement_tx_stream </th>
<th> measurement_channel</th>
<th> measurement_tput_mean</th>
<th>measurement_txbw </th>
<th>measurement_txmode </th>
<th>measurement_txpower_0 </th>
<th>measurement_txpower_1 </th>
<th>measurement_txpower_2 </th>
<th> measurement_txpower_3</th>
<th> measurement_evm_0</th>
<th>measurement_evm_1 </th>

<th> measurement_evm_2 </th>
<th> measurement_evm_3 </th>
<th>measurement_ap_rssi </th>
<th>measurement_plot </th>
<th> measurement_rx_mcs </th>
<th>measurement_tx_mcs </th>
<th> configuration_apname </th>
<th> configuration_staname </th>
<th>configuration_group </th>
<th> configuration_test_duration </th>
<th> targets_status </th>
<th>targets_date </th>
<th>targets_certification</th></tr>';}while ($row = mysqli_fetch_assoc($res1)) {$produit .= '<tr>
<td>' . $row['wlan_test_run_date'] . '</td>
<td>' . $row['wlan_test_run_time'] . '</td>
<td>' . $row['tester_company'] . '</td>
<td>' . $row['tester_operator_name'] . '</td>
<td>' . $row['location_site'] . '</td>
<td>' . $row['location_description'] . '</td>
<td>' . $row['location_name'] . '</td>
<td>' . $row['location_distance'] . '</td>
<td>' . $row['location_floor'] . '</td>
<td>' . $row['location_thin_wall'] . '</td>
<td>' . $row['location_thick_wall'] . '</td>
<td>' . $row['location_pathloss'] . '</td>
<td>' . $row['location_conducted_attenuation'] . '</td>
<td>' . $row['Wlan_test_run_info'] . '</td>
<td>' . $row['ap_manufacturer'] . '</td>
<td>' . $row['ap_model'] . '</td>
<td>' . $row['ap_serial_number'] . '</td>
<td>' . $row['ap_hw_version'] . '</td>
<td>' . $row['ap_sw_version'] . '</td>
<td>' . $row['ap_wifi_driver_version'] . '</td>
<td>' . $row['ap_certification'] . '</td>
<td>' . $row['ap_calibration_version'] . '</td>
<td>' . $row['sta_manufacturer'] . '</td>
<td>' . $row['sta_model'] . '</td>
<td>' . $row['sta_serial_number'] . '</td>
<td>' . $row['sta_hw_version'] . '</td>
<td>' . $row['sta_sw_version'] . '</td>
<td>' . $row['sta_wifi_driver_version'] . '</td>
<td>' . $row['configuration_band'] . '</td>
<td>' . $row['configuration_modulation'] . '</td>
<td>' . $row['configuration_bandwidth'] . '</td>
<td>' . $row['configuration_channel'] . '</td>
<td>' . $row['configuration_transfert_type'] . '</td>
<td>' . $row['configuration_radiated_mode'] . '</td>
<td>' . $row['configuration_conducted_attenuation'] . '</td>
<td>' . $row['configuration_security'] . '</td>
<td>' . $row['configuration_protocol'] . '</td>
<td>' . $row['configuration_anglev'] . '</td>
<td>' . $row['configuration_angleh'] . '</td>
<td>' . $row['measurement_throughput'] . '</td>
<td>' . $row['measurement_sta_rssi'] . '</td>
<td>' . $row['measurement_rx_rate'] . '</td>
<td>' . $row['measurement_tx_rate'] . '</td>
<td>' . $row['measurement_rx_stream'] . '</td>
<td>' . $row['measurement_tx_stream'] . '</td>
<td>' . $row['measurement_channel'] . '</td>
<td>' . $row['measurement_tput_mean'] . '</td>
<td>' . $row['measurement_txbw'] . '</td>
<td>' . $row['measurement_txmode'] . '</td>
<td>' . $row['measurement_txpower_0'] . '</td>
<td>' . $row['measurement_txpower_1'] . '</td>
<td>' . $row['measurement_txpower_2'] . '</td>
<td>' . $row['measurement_txpower_3'] . '</td>
<td>' . $row['measurement_evm_0'] . '</td>
<td>' . $row['measurement_evm_1'] . '</td>
<td>' . $row['measurement_evm_2'] . '</td>
<td>' . $row['measurement_evm_3'] . '</td>

<td>' . $row['measurement_ap_rssi'] . '</td>
<td>' . $row['measurement_plot'] . '</td>
<td>' . $row['measurement_rx_mcs'] . '</td>
<td>' . $row['measurement_tx_mcs'] . '</td>
<td>' . $row['configuration_apname'] . '</td>
<td>' . $row['configuration_staname'] . '</td>
<td>' . $row['configuration_group'] . '</td>
<td>' . $row['configuration_test_duration'] . '</td>
<td>' . $row['targets_status'] . '</td>
<td>' . $row['targets_date'] . '</td>
<td>' . $row['targets_certification'] . '</td></tr>';}$compteur = $compteur +1; }echo $produit;
}

}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
link rel="stylesheet" type="text/javascript" href="httpscdnjs.cloudflare.comajaxlibsjquery2.1.3jquery.min.js">
<link rel="stylesheet" type="text/css" href="Feuille_ajouter.css">


<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.css" />
</body>
</html>
A voir également:

2 réponses

jordane45 Messages postés 38152 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 3 mai 2024 4 652
30 août 2018 à 01:23
Bonjour
Tu dois séparer la partie affichage de ta partie génération de fichier...
0
jordane45 Messages postés 38152 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 3 mai 2024 4 652
30 août 2018 à 01:25
Et encore une fois.... poste ton code correctement !!!!
Ce n'est pas compliqué quand même....

dernier rappel

Je te redonne le lien qui explique comment faire: https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
0