Frontend: < /p>
function download_table() {
const table = document.getElementById("Dtf-table");
if (!table) {
alert("Table is not detected");
return;
}
const html = table.outerHTML;
fetch("factory/generate_excel1.php", {
method: "POST",
headers: {
"Content-Type": "text/plain" // send raw HTML as plain text
},
body: html
})
.then(response => response.text())
.then(fileName => {
const a = document.createElement("a");
a.href = `factory/${fileName.trim()}`; // path to saved file
a.download = ""; // let browser pick the filename
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
})
.catch(error => {
console.error("
});
}
< /code>
Бэкэнд: < /p>
require __DIR__ . '/../../php/vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Reader\Html;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
try {
$rawHtml = file_get_contents("php://input");
if (!$rawHtml) {
throw new Exception("
}
// Load HTML into Spreadsheet
$reader = new Html();
$spreadsheet = $reader->loadFromString($rawHtml);```
Подробнее здесь: https://stackoverflow.com/questions/797 ... hp-backend
Мобильная версия