Trying to get a table to print to an excel sheet. All i get is page not found in my browser. I have the link pointing to
shiplistxls.php/shiplistxls.xls
Here is the code for the excel sheet.
<?
Header("Content-Type: application/vnd.ms-excel");
$query_text = "SELECT * FROM shiplist";
$result = mysql_query($query_text);
$fieldcounts = mysql_num_fields($result);
for($i = 0; $i < $fieldcounts; $i++) {
$fieldtype = mysql_fetch_field($result, $i);
echo "$fieldtype->name [$fieldtype->type]\t";
}
echo "\n";
while ($myrow = mysql_fetch_array($result)) {
for($i = 0; $i < $fieldcounts; $i++) {
$fieldname = mysql_field_name($result, $i);
echo "$myrow[$fieldname]\t";
}
echo "\n";
}
?>
table to excel
Moderator: General Moderators
Hello.I got this to output fine in Mozilla. But it does nor being up Excel in Explorer. Why is this happeneing??
if(!$getuserline[realname])
{
header("Location: login.php");
}
else
{header("Content-Type: application/vnd.ms-excel");
$query_text = "SELECT * FROM shiplist";
$result = mysql_query($query_text);
$fieldcounts = mysql_num_fields($result);
for($i = 0; $i < $fieldcounts; $i++) {
$fieldtype = mysql_fetch_field($result, $i);
echo "$fieldtype->name [$fieldtype->type]\t";
}
echo "\n";
while ($myrow = mysql_fetch_array($result)) {
for($i = 0; $i < $fieldcounts; $i++) {
$fieldname = mysql_field_name($result, $i);
echo "$myrow[$fieldname]\t";
}
echo "\n";
}
}
?>
if(!$getuserline[realname])
{
header("Location: login.php");
}
else
{header("Content-Type: application/vnd.ms-excel");
$query_text = "SELECT * FROM shiplist";
$result = mysql_query($query_text);
$fieldcounts = mysql_num_fields($result);
for($i = 0; $i < $fieldcounts; $i++) {
$fieldtype = mysql_fetch_field($result, $i);
echo "$fieldtype->name [$fieldtype->type]\t";
}
echo "\n";
while ($myrow = mysql_fetch_array($result)) {
for($i = 0; $i < $fieldcounts; $i++) {
$fieldname = mysql_field_name($result, $i);
echo "$myrow[$fieldname]\t";
}
echo "\n";
}
}
?>
I've been doing writes to excel myself and I've done it like this:
And this works perfectly. Of course, you need to have excel on your webserver for this to work in the first place...
Code: Select all
#Create an object instance
$excel= new COM("Excel.Application") or die("Excel could not be started");
#pop open the Excel application
$excel->Visible= 1;
#turn off alerts
$excel->DisplayAlerts= 0;
$Directory= _Dir ."po_excel/" . $country_id . ".xls";
#specify workbook
$workbook= $excel->Workbooks->Open($Directory);
#Activate the first worksheet
$sheets= $workbook->Worksheets(1);
$sheets->activate;
# Cells(5,4) => Permanent Employee Name
$cell= $sheets->Cells(5,4);
$cell->activate;
$cell->value= $full_name;
// More cells
$sheets->Calculate;
$Directory= _Dir ."po_excel/" . $SessionID . ".xls";
#save
$excel->Workbooksї1]->SaveAs($Directory);
#close the application
$excel->Quit();
unset($sheets);
unset($cell);
unset($workbook);
unset($excel);