Having problem with exporting some data numbers to Excel!!!
Posted: Tue Mar 10, 2009 10:13 am
Hi there!
The problem is about Exporting some decimal numbers to excel. Having a php program which make the export to excel, and all works fine, till discovering a problem with the Regional Options from Windows. If the Decimal symbol from the Windows settings is set as "comma" than the export is fine with all data, and the real numbers with comma looks as numbers like it should be. But when the Decimal symbol is set "dot" than all my numbers with decimals exported in excel appear like calendaristic datas.
How can i fix the problem, without modifying the settings for each windows. All i just wanna do is to export the numbers like numbers in excel, no matter how is set the Decimal Symbol in Regional Options of the OS.
Here i'll put some code, for seeing how i do the export:
Some help wil be greatly appreciated!!!
The problem is about Exporting some decimal numbers to excel. Having a php program which make the export to excel, and all works fine, till discovering a problem with the Regional Options from Windows. If the Decimal symbol from the Windows settings is set as "comma" than the export is fine with all data, and the real numbers with comma looks as numbers like it should be. But when the Decimal symbol is set "dot" than all my numbers with decimals exported in excel appear like calendaristic datas.
How can i fix the problem, without modifying the settings for each windows. All i just wanna do is to export the numbers like numbers in excel, no matter how is set the Decimal Symbol in Regional Options of the OS.
Here i'll put some code, for seeing how i do the export:
Code: Select all
<?php
include ("../sesiuni/conectare.php");
session_start();
header("Content-Type: application/vnd.ms-excel;");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("content-disposition: attachment;filename=Raport1.xls");
header("Cache-Control: public");
header("Content-Description: File Transfer");
print "<META HTTP-EQUIV='Content-type' CONTENT='application/vnd.ms-excel;charset=utf-8'>";
print "<b>Raport <b><br>";
$nume_utilizator = $_SESSION['nume_utilizator'];
$id_ft = $_SESSION['lastid'];
$query = "SELECT
specie_cultura.denumire_specie,
ft.id_ft,
specie_cultura.id_specie,
ft.suprafata_totala,
ft.roada_scontata,
ft.pret_unitar,
ft.cantitate_material_sad,
ft.pret_unitar_material_sad,
ft.pret_lubrifiant,
ft.suma_defalcari
FROM
ft
LEFT JOIN specie_cultura ON ( ft.id_specie = specie_cultura.id_specie) WHERE id_ft=$id_ft";
$result = pg_query($query);
// print the random numbers
echo ' <b>Fisa tehnologica de producere a legumelor</b>
<table border=1 cellpadding="1" cellspacing="1">
<tr align="center">
<td>Nr.</td>
<td>Denumire specie</td>
<td>Suprafata <br>
de producere</td>
<td>Cantitate material <br>săditor (pl/ha, kg/ha)</td>
<td>Pret unitar,<br>
material saditor</td>
<td>Recolta planificata<br>(la 1 ha)</td>
<td>Pretul mediu<br>de comercializare<br>a productiei<br>(MDL/kg)</td>
</tr>';
$i=1;
while($row = pg_fetch_array($result))
{
echo '<tr align="right">
<td align="center">'.$i++.'</td>
<td align="left">'.$row['denumire_specie'] .'</td>
<td>'.$row['suprafata_totala'].'</td>
<td>'.$row['cantitate_material_sad'].'</td>
<td>'.$row['pret_unitar_material_sad'].'</td>
<td>'.$row['roada_scontata'].'</td>
<td>'.$row['pret_unitar'].'</td>
</tr>';
}
echo " </table>";
// **********************************************raportul 4**************************
//$id_ft = $_SESSION['lastid'];
$query = "SELECT DISTINCT
profit_brut.id_ft,
profit_brut.cheltuieli_mat_sad,
profit_brut.cheltuieli_chimie,
profit_brut.cheltuieli_tehnologice,
profit_brut.cheltueli_totale,
profit_brut.cheltuieli_suplimentare,
profit_brut.venituri_totale,
profit_brut.profit
FROM
profit_brut
WHERE
profit_brut.id_ft = $id_ft";
$result = pg_query($query);
// print the random numbers
echo '<b>Calcularea Profitului Brut/Venituri din Vinzari</b><br><br>
<table border=0 cellpadding="1" cellspacing="1">';
$i=1;
while($row = pg_fetch_array($result))
{
echo '
<tr>
<td></td><td><div align="left">Cheltuieli tehnologice:</div></td><td><strong>'.[color=#BF0000]round($row['cheltuieli_tehnologice'],2)[/color] .'</strong></td>
</tr>
<tr>
<td></td><td><div align="left">Cheltuieli materiale pentru producere:</div></td>
<td><strong>'.r[color=#BF0000]ound($row['cheltuieli_chimie'],2)[/color].'</strong></td>
</tr>
<tr>
<td></td><td><div align="left">Cheltuieli Material Saditor:</div></td>
<td><strong>'.round($row['cheltuieli_mat_sad'],2).'</strong></td>
</tr>
<tr>
<td></td><td><div align="left">Cheltuieli Suplimentare (%):</div></td>
<td><strong>'.[color=#BF0000]round($row['cheltuieli_suplimentare'],2)[/color].'</strong></td>
</tr>
<tr>
<td></td><td><div align="left">Cheltuieli Totale:</div></td><td><strong>'.[color=#BF0000]round($row['cheltueli_totale'],2)[/color].'</strong></td>
</tr>
<tr>
<td></td><td><div align="left">Venit:</div></td><td><strong>'.[color=#BF0000]round($row['venituri_totale'],2)[/color].'</strong></td>
</tr>
<tr>
<td></td><td><div align="left"><b>Profit:</b></div></td><td><strong>'.round($row['profit'],2).'</strong></td>
</tr>';
}
echo "</table>";
?>
?>