31. 07. 2012. | #1 |
profesionalac
Professional
Datum učlanjenja: 30.08.2010
Poruke: 201
Hvala: 10
640 "Hvala" u 14 poruka
|
Export to Excel (PDF)
Pozdrav ekipi. Hocu da exportujem podatke iz mysql tabele u excel, ali imam i nasa slova sa kvakicama. Ja sam malo istrazivao i uspio doci do ovoga:
Kôd:
<?php include('include/config.php'); $select = "SELECT * from radnik where pozicija ='Uprava' "; $export = mysql_query ( $select ) or die ( "Sql error : " . mysql_error( ) ); $fields = mysql_num_fields( $export ); for ( $i = 0; $i < $fields; $i++ ) { $header .= mysql_field_name( $export , $i ) . "\t"; } while( $row = mysql_fetch_row( $export ) ) { $line = ''; foreach( $row as $value ) { if ( ( !isset( $value ) ) || ( $value == "" ) ) { $value = "\t"; } else { $value = str_replace( '"' , '""' , $value ); $value = '"' . $value . '"' . "\t"; } $line .= $value; } $data .= trim( $line ) . "\n"; } $data = str_replace( "\r" , "" , $data ); if ( $data == "" ) { $data = "\n(0) Pronadjeno zapisa!\n"; } header("Content-Type: application/vnd.ms-excel; charset=utf-8"); header("Content-Disposition: attachment; filename=radnici.xls"); header("Pragma: no-cache"); header("Expires: 0"); print "$header\n$data"; |
31. 07. 2012. | #2 |
Pukovnik u penziji
Grand Master
|
Jesu li podaci u tabeli uredni ?
|
31. 07. 2012. | #3 |
profesionalac
Professional
Datum učlanjenja: 30.08.2010
Poruke: 201
Hvala: 10
640 "Hvala" u 14 poruka
|
Da uredni si to mi ne predstavlja problem !
|
31. 07. 2012. | #4 |
Miloš Ranđelović
Certified
Datum učlanjenja: 16.05.2008
Lokacija: Beograd/Niš
Poruke: 66
Hvala: 26
23 "Hvala" u 14 poruka
|
Da li ti je taj .php fajl u UTF-8 charsetu?
__________________
Nisam zgodan, al' sam zato nezgodan. |
31. 07. 2012. | #5 |
profesionalac
Professional
Datum učlanjenja: 30.08.2010
Poruke: 201
Hvala: 10
640 "Hvala" u 14 poruka
|
|
31. 07. 2012. | #6 |
banned
Professional
Datum učlanjenja: 04.06.2005
Poruke: 371
Hvala: 0
738 "Hvala" u 83 poruka
|
__________________
Don't look at me; I'm lost too. “If you can't dazzle them with brilliance, baffle them with bul*s**t.” |
31. 07. 2012. | #7 |
Ivan Dilber
Sir Write-a-Lot
|
dodaj BOM na pocetak
__________________
Leadership is the art of getting people to want to do what you know must be done. |
01. 08. 2012. | #8 |
profesionalac
Professional
Datum učlanjenja: 30.08.2010
Poruke: 201
Hvala: 10
640 "Hvala" u 14 poruka
|
|
01. 08. 2012. | #9 |
banned
Professional
Datum učlanjenja: 04.06.2005
Poruke: 371
Hvala: 0
738 "Hvala" u 83 poruka
|
umesto:
PHP kôd:
PHP kôd:
__________________
Don't look at me; I'm lost too. “If you can't dazzle them with brilliance, baffle them with bul*s**t.” |
01. 08. 2012. | #10 |
Ivan Dilber
Sir Write-a-Lot
|
Starije verzije Excela ne kapiraju UTF8 BOM na pocetku, pa mozes da probas i ovako da saljes fajl:
PHP kôd:
$filename je ime koje se nudi korisniku kod snimanja, $csv je string sa CSV podacima ($header i $data u tvom slucaju). Mana je sto moras da imas PHP koji podrzava mb_convert_encoding() f-ju, ali zato radi sa svim zivim Excelima koje sam probao...
__________________
Leadership is the art of getting people to want to do what you know must be done. Poslednja izmena od ivanhoe : 01. 08. 2012. u 16:44. |
|
|