Posts Tagged ‘content’

Open .xls HTML content with Open Office

It looks like there’s a little bug in Open Office… If you have an .xls file with HTML content, if you open it with Microsoft Excel, it will look like an Excel table, but if you try to open it with Open Office, the HTML content will be displayed instead of the table.

Here’s how you can make it to work:

- instead of trying opening the file by double clicking it from Explorer, open a new, clean Open Office Calc spreadsheet, and open the file by selecting from the menu: File->Open.

Here is a small code to test it:

a b c
1 2 3
4 5 6
7 8 9

Create Excel file from PHP with tables using headers

Did You ever needed to create pure and simple Excel spreadsheets from php? Are you tired with complicated classes, large and nonsense code? Here is a tiny code sample, showing how easy it  is to create Excel files directly from a php file. I won’t comment the lines, as the code is obvious…

$file_name = “myfile.xls”;

header(‘Pragma: public’);
header(‘Expires: 0′);
header(‘Cache-Control: must-revalidate, post-check=0, pre-check=0′);
header(‘Cache-Control: public’);
header(‘Content-Description: File Transfer’);
header(‘Content-Type: text/xls; name=”‘ . $file_name . ‘”‘);
header(‘Content-Disposition: attachment; filename=”‘ . $file_name . ‘”‘);
header(‘Content-Transfer-Encoding: binary’);

$content = ‘<table>
<tr>
<td>Header1 (A)</td>
<td>Header2 (B)</td>
<td>Header3 (C)</td>
</tr>
<tr>
<td>Content 1A</td>
<td>Content 1B</td>
<td>Content 1C</td>
</tr>
<tr>
<td>Content 2A</td>
<td>&nbsp;</td>
<td>Content 2C</td>
</tr>
</table>’;

echo $content