Dear all,
I have exists excel file on server. Now, I want output the file by php. I have this code:

$file = "test.xls";
$file=basename($file);
if (file_exists($file)) {
    header('Content-Type: application/ms-excel');
    header('Content-Disposition: attachment; filename='.$file);
    ob_clean();
    flush();
    readfile($file);
    exit;
}

When I click download button, I can open file, but appear "missing css file" dialog and content of this file have replaced by special character.
Anyone help me? Thank you in advanced.

Recommended Answers

All 3 Replies

Thanks, the library used to create excel file and then export to client side. But I have already excel file and I want to output it by PHP. My problem is the excel file's content was replaced by CSS file in html.. :(

Member Avatar for iamthwee

So you need to read the cells in the excel and dump tables.

E.g. read excel cell1

table
--row
---excel value
--closerow
close table

etc.

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.