hi frds if anyone knows how to import and export table details from db in the form of excel sheet please guide me.note it should cum as xls sheet

Dani AI

Generated

Building on and (who pointed to manual GUI approaches), below are practical, programmatic ways to produce/import spreadsheet-readable files from PHP/MySQL, plus quick troubleshooting points you can apply immediately.

CSV streaming is the simplest and uses the least memory. Send proper headers, emit a UTF-8 BOM so Excel on Windows detects UTF-8, and stream rows with fputcsv to php://output. Example pattern:

<?php
header('Content-Type: text/csv; charset=UTF-8');
header('Content-Disposition: attachment; filename="export.csv"');
echo "\xEF\xBB\xBF"; // UTF-8 BOM for Excel
$out = fopen('php://output', 'w');
fputcsv($out, ['id','name','email']); // header row
$stmt = $mysqli->query("SELECT id,name,email FROM mytable");
while ($row = $stmt->fetch_assoc()) {
    fputcsv($out, $row);
}
fclose($out);
exit;

When you need true Excel files (formatting, large row/column support, cell types), use a maintained library such as PhpSpreadsheet to write .xlsx. Populate with arrays or iterate rows and write to php://output with the correct MIME. For very large exports, consider a streaming writer (Box/Spout) to avoid memory spikes.

Common gotchas and quick fixes:

  • Choose CSV for simple data; choose .xlsx for formatting or >65k rows. Old .xls has ~65,536 row/256 column limits; .xlsx supports 1,048,576 rows. See Excel limits for details.
  • If numeric strings become scientific notation, force the cell to text or prefix with a single quote when writing.
  • Excel misreads dates: format or write ISO8601 strings and let Excel parse them, or set explicit cell formats.
  • For large exports, fetch DB rows in chunks, disable output buffering, and increase memory_limit/max_execution_time only as a last resort.

References: fputcsv manual, PhpSpreadsheet (PHPOffice), Box/Spout streaming writer, .

Recommended Answers

All 2 Replies

You can do it manually by using PHPMyAdmin.
To read from a spreadsheet in a program, see this.
To export to xls from a program, have a look at .

what details? Structure?
u can just drag the mouse over the myPhpAdmin page and select the table, then copy-paste it to XLS...
don't have a better idea..
hope this helps.

p.s
u can export all the info really nicely as a pdf via the Designer view

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.