Hi
Is there anyone who know How to capute a whole HTML file and convert itto Excel
for example

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="description" content="">
<title>Fourth Year Computer Technology Time Table</title>
</head>
<body>
<p>&nbsp;</p>
<p>&nbsp;</p>

<table cellspacing='4' cellpadding='4' border="1" align="center">
<tr>
<td>Day</td>
<td>Time</td>
<td>Unit</td>
<td>Lecturer</td>
</tr>

<tr>
<td>Monday</td>
<td>8.00am To 1.00 Pm </td>
<td>BCT 2406 Project Research and definition</td>
<td>&nbsp;</td>
</tr>

<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>


<tr>
<td>Tuesday</td>
<td>8.00am To 10.00am </td>
<td>BCT 2405 Client Server Systems & Computing</td>
<td>JB Kariuki</td>

</tr>
<tr>
<td>&nbsp;</td>
<td>12.00noon To 2.00PM</td>
<td>BCT 2405 Computer Graphics System</td>
<td>Kihongo</td>

</tr>
<tr>
<td>&nbsp;</td>
<td>2.00PM To 5.00 PM </td>
<td>BCT 2405 Computer Graphics System</td>
<td>Kihongo</td>

</tr>


<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>

<tr>
<td>Wednesday</td>
<td>7.00am To 10.00am </td>
<td>BCT 2405 Client Server Systems & Computing</td>
<td>JB Kariuki</td>

</tr>
<tr>
<td>&nbsp;</td>
<td>11.00noon To 1.00PM</td>
<td>BCT 2403 Knowledge Based Systems</td>
<td>George Okeyo</td>
</tr>

<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>

<tr>
<td>Thursday</td>
<td>7.00am To 10.00am </td>
<td>BCT 2403 Knowledge Based Systems</td>
<td>George Okeyo</td>

</tr>

<tr>
<td>&nbsp;</td>
<td>11.00am To 12.00 PM </td>
<td>BCT 2401 Operations Research</td>
<td>P Kihara</td>

</tr>

<tr>
<td>&nbsp;</td>
<td>12.00am To 2.00 PM </td>
<td>BCT 2404 Decision Support System</td>
<td>L Mburu</td>

</tr>
<tr>
<td>&nbsp;</td>
<td>3.00am To 6.00 PM </td>
<td>BCT 2404 Decision Support System</td>
<td>L Mburu</td>

</tr>

<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>


<tr>
<td>Friday</td>
<td>9.00am To 10.00am </td>
<td>BCT 2401 Operations Research</td>
<td>P Kihara</td>

</tr>

<tr>
<td>&nbsp;</td>
<td>11.00am To 2.00 PM </td>
<td>Research Methodology</td>
<td>L Mengo</td>

</tr>

<tr>
<td>&nbsp;</td>
<td>2.00PM To 4.00 PM </td>
<td>Research Methodology</td>
<td>L Mengo</td>

</tr>

<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>

</table>

</body>
</html>

Dani AI

Generated

Practical ways to get an HTML table into Excel (short, reliable paths):

  • Quick, one-off: copy the table from the browser and paste into Excel (as suggested). Fast and foolproof for small tables but manual.
  • Fast automated hack: serve the HTML table as a download that Excel will open. This is the trick used; it works well for simple tables but is a compatibility hack (Excel may warn if extension and content do not match, and advanced Excel features are not available).
  • Robust, production-safe: export CSV when you only need rows/columns, or use a native XLSX writer when you need cell types, formatting, multiple sheets, or large exports.

Concrete tips that answer the other points raised in the thread (for and ):

  • CSV basics: quote fields that contain commas or newlines, escape internal quotes by doubling them, and prepend the UTF-8 BOM (the three bytes shown as \xEF\xBB\xBF) if you want Windows Excel to detect UTF-8 reliably.
  • Preserving long numbers and exact digits: Excel uses 15-digit numeric precision. If your value has more than 15 significant digits (or must retain leading zeros), export it as text. Options: make the column Text in Excel, prefix the value with an apostrophe, or output a formula-style cell like ="123456789012345678" so Excel treats it as text.
  • Formatting control: the HTML->Excel trick can carry some Excel-specific CSS (for example the Microsoft "mso-*" styles) but results vary by Excel version. For full control (number formats, column types, styles), use a modern XLSX library so you can explicitly set each cell type and stream large files.

Troubleshooting notes:

  • If Excel mangles encoding, check the BOM and Content-Type you send.
  • If columns import as dates or numbers unexpectedly, force them to text as above.
  • For very large exports, prefer a streaming writer to avoid memory problems.

Credit: this builds on the copy/paste idea from and the download/header approach from , and addresses the numeric-format question raised by .

Recommended Answers

All 6 Replies

easiest way I know is to view it in a web browser and then highlight the information and copy it to excel.

use the following code:

i have just included the first row and hope you will not have problems with the rest:

<?php


echo "<table cellspacing='4' cellpadding='4' border=1 align=center>";
echo"<tr>";
echo"<td>Day</td>";
echo"<td>Time</td>";
echo"<td>Unit</td>";
echo"<td>Lecturer</td>";
echo"</tr>";

echo"</table>";















header("Content-type: application/octet-stream");

# replace excelfile.xls with whatever you want the filename to default to
header("Content-Disposition: attachment; filename=excelfile.xls");
header("Pragma: no-cache");
header("Expires: 0");


?> 
  
  
</p>
</body>
</html>

please if found this code helpful, can you add my reputation

This works for me !!! Thank you very much !!!

can i format the table columns? like tell the column to act as a number?
i getting 1231 instead 1.23443E+14 of 123443211234000

thanx

Hi! A little late, but.... I found the following 'library' easy to use.

Using php, could you pass what you want to pass into excel via a variable and your set.

Hope it helps.

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.