Page 1 of 1
MySql-Excel - only dates export..no strings
Posted: Thu Jul 20, 2006 1:42 pm
by kbrown3074
I created a php page to create a excel sheet that puts data into the sheet by exporting the html table codes and such. Any data that has a date value exports fine, but anything that is a string will not export. I am using a 'foreach' loop from a 'mysql_fetch_row' variable. The print line is: print("<td>$dbrow[$col_num]</td>")
Is there a way to modify the print line to send the info as a string, or do I have to set up some kind of excel formatting as I create the sheet?
Posted: Thu Jul 20, 2006 2:01 pm
by RobertGonzalez
Can you post your actual code so we can see what is happening?
Posted: Thu Jul 20, 2006 2:10 pm
by kbrown3074
Just a quick background..the dbase and the tables do exist so that part is not a problem. The spreadsheet opens fine under excel on a windows box BUT the html code results display in openoffice. This will be used mainly by a windows user so that is secondary at this point.
<?
$dbase=$_GET['dbase'];
$edt1=$_GET['edt1'];
$edt2=$_GET['edt2'];
$filename=$_GET['filename'];
$tsrnum=$_GET['tsrnum'];
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$filename.csv");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Expires: 0");
$pagehead = "AGENT " . $tsrnum . " REPORT";
?>
<strong>Agent State Report</strong>
<table border="1">
<tr>
<td bgcolor="#FFFFCC"></td>
<?
$dbcon = mysql_connect("localhost", "test", "test");
mysql_select_db($dbase,$dbcon);
print("<table border=1>\n");
print("<tr>\n");
print("<td bgcolor=#FFFFCC></td>\n");
$export="select * from $edt2";
$expresult = mysql_query($export,$dbcon) or die (mysql_error());
$num_fields = mysql_num_fields($expresult);
while($rowx = mysql_fetch_field($expresult))
{
print("<td bgcolor=\"#FFFFCC\">");
print("$rowx->name");
print("</td>");
}
print("</tr>\n");
while($dbrow = mysql_fetch_row($expresult))
{
print("<tr>");
$col_num = 0;
foreach($dbrow as $key=>$value)
{
if($dbrow[$col_num] > 0)
{
print("<td>$dbrow[$col_num]</td>");
}
else
{
print("<td> </td>");
}
$col_num++;
}
print("</tr>\n");
}
print("</table>\n");
?>
Posted: Thu Jul 20, 2006 10:24 pm
by RobertGonzalez
Please use bbCode (
Code: Select all
or [ php ]) tags when posting code.
[quote="kbrown3074"]Just a quick background..the dbase and the tables do exist so that part is not a problem. The spreadsheet opens fine under excel on a windows box BUT the html code results display in openoffice. This will be used mainly by a windows user so that is secondary at this point.
[syntax=php]<?php
$dbase=$_GET['dbase'];
$edt1=$_GET['edt1'];
$edt2=$_GET['edt2'];
$filename=$_GET['filename'];
$tsrnum=$_GET['tsrnum'];
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$filename.csv");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Expires: 0");
$pagehead = "AGENT " . $tsrnum . " REPORT";
?>
<strong>Agent State Report</strong>
<table border="1">
<tr>
<td bgcolor="#FFFFCC"></td>
<?php
$dbcon = mysql_connect("localhost", "test", "test");
mysql_select_db($dbase,$dbcon);
print("<table border=1>\n");
print("<tr>\n");
print("<td bgcolor=#FFFFCC></td>\n");
$export="select * from $edt2";
$expresult = mysql_query($export,$dbcon) or die (mysql_error());
$num_fields = mysql_num_fields($expresult);
while($rowx = mysql_fetch_field($expresult))
{
print("<td bgcolor="#FFFFCC">");
print("$rowx->name");
print("</td>");
}
print("</tr>\n");
while($dbrow = mysql_fetch_row($expresult))
{
print("<tr>");
$col_num = 0;
foreach($dbrow as $key=>$value)
{
if($dbrow[$col_num] > 0)
{
print("<td>$dbrow[$col_num]</td>");
}
else
{
print("<td> </td>");
}
$col_num++;
}
print("</tr>\n");
}
print("</table>\n");
?>
[/quote]