На самом деле, я хотел бы запустить автоматическую загрузку сгенерированного файла Excel на странице Ext JS.Есть ли пример исходного кода, который может помочь?Найти ниже моего личного исходного кода, который на самом деле не работает (эта функция вызывается при нажатии на кнопку «экспортировать CSV»:
function exportCsv($criteresRecherche)
{
$data = $this->executeRequete($sql);
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: attachment; filename=\"export_commandes.csv\"");
$colToShow = array(
"fournisseur"=>"Fournisseur",
"lieudepart"=>"Départ",
"datedepartprevue"=> "Date Dep Prevu",
"confirme"=> "Emb.",
"modepaiement"=>"Pmt.",
"incoterm"=>"Inc.",
"containers"=>"Containers",
"nocde"=>"CDE BIE N°",
"nocde_associees"=>"CDE BIE ASSOC",
"nocde_erp"=>"N° GNX",
"aa"=>"Acheteur",
"acp"=>"Acheteur CP",
"resp_suivi"=>"Suivi par",
"shippingmarks"=>"Shp.",
"artwrk"=>"Art.",
"positionetiquette"=>"Pos.",
"relance1mois"=>"Rel",
"echantillon"=>"Ech.",
"certification"=>"Cer.",
"consolidation"=>"Cns.",
"etiquette_securite"=>"Sec.",
"devise"=>"Dev.",
"montant_total"=>"Total Achat",
"statut"=>"Statut",
"datecreation"=>"Date de création",
"dateintegration"=>"Date intégration"
);
echo $this->getHtmlToCsv($data, $colToShow);
exit();
}
Ниже приведена функция, генерирующая файл CSV.
function getHtmlToCsv($elements, $colToShow)
{
$retour = "<table >"."\n";
$retour .= "<tr class=\"titre\">"."\n";
if ($colToShow && is_array($colToShow)) {
foreach ($colToShow as $col => $libColonne) {
$retour .= "<td>".strtr(
$libColonne, get_html_translation_table(HTML_ENTITIES, ENT_QUOTES, "ISO-8859-1")
)."</td>"."\n";
}
}
$retour .= "</tr>"."\n";
foreach ($elements as $element) {
$retour .= "<tr>"."\n";
$retour .= "<td>".strtr(
$element['FOURNISSEUR'], get_html_translation_table(HTML_ENTITIES, ENT_QUOTES, "ISO-8859-1")
)."</td>"."\n" ;
$retour .= "<td>".strtr(
$element['LIEUDEPART'], get_html_translation_table(HTML_ENTITIES, ENT_QUOTES, "ISO-8859-1")
)."</td>"."\n" ;
$retour .= "<td>".strtr(
$element['DATEDEPARTPREVUE'], get_html_translation_table(HTML_ENTITIES, ENT_QUOTES, "ISO-8859-1")
)."</td>"."\n" ;
$retour .= "<td>".strtr(
$element['CONFIRME'], get_html_translation_table(HTML_ENTITIES, ENT_QUOTES, "ISO-8859-1")
)."</td>"."\n" ;
$retour .= "<td>".strtr(
$element['MODEPAIEMENT'], get_html_translation_table(HTML_ENTITIES, ENT_QUOTES, "ISO-8859-1")
)."</td>"."\n" ;
$retour .= "</tr>"."\n".strtr(
$element['INCOTERM'], get_html_translation_table(HTML_ENTITIES, ENT_QUOTES, "ISO-8859-1")
)."</td>"."\n" ;
$retour .= "</tr>"."\n".strtr(
$element['CONTAINER'], get_html_translation_table(HTML_ENTITIES, ENT_QUOTES, "ISO-8859-1")
)."</td>"."\n" ;
$retour .= "</tr>"."\n".strtr(
$element['NOCDE'], get_html_translation_table(HTML_ENTITIES, ENT_QUOTES, "ISO-8859-1")
)."</td>"."\n" ;
$retour .= "</tr>"."\n".strtr(
$element['NOCDE_ASSOCIEES'], get_html_translation_table(HTML_ENTITIES, ENT_QUOTES, "ISO-8859-1")
)."</td>"."\n" ;
$retour .= "</tr>"."\n".strtr(
$element['NOCDE_ERP'], get_html_translation_table(HTML_ENTITIES, ENT_QUOTES, "ISO-8859-1")
)."</td>"."\n" ;
$retour .= "</tr>"."\n".strtr(
$element['AA'], get_html_translation_table(HTML_ENTITIES, ENT_QUOTES, "ISO-8859-1")
)."</td>"."\n" ;
$retour .= "</tr>"."\n".strtr(
$element['ACP'], get_html_translation_table(HTML_ENTITIES, ENT_QUOTES, "ISO-8859-1")
)."</td>"."\n" ;
$retour .= "</tr>"."\n".strtr(
$element['RESP_SUIVI'], get_html_translation_table(HTML_ENTITIES, ENT_QUOTES, "ISO-8859-1")
)."</td>"."\n" ;
$retour .= "</tr>"."\n".strtr(
$element['SHIPPINGMARKS'], get_html_translation_table(HTML_ENTITIES, ENT_QUOTES, "ISO-8859-1")
)."</td>"."\n" ;
$retour .= "</tr>"."\n";
}
$retour .= "</table>"."\n";
$retour .= "<br>";
// Balise qui force le type a texte pour ne subir aucun formattage excel
$style = "<style>\n"
. "td{mso-number-format:\"\@\"; border-bottom: 1px solid black; border-right: 1px solid black;}\n"
. ".titre { font-size: 16px; font-weight: bold;}\n"
. "table { border: 1px solid black;}\n"
. "</style>\n";
$retour = utf8_decode($retour);
return $retour ;
}