Pogledajte određenu poruku
Staro 01. 08. 2012.   #11
slavkan
profesionalac
Professional
 
Datum učlanjenja: 29.08.2010
Poruke: 201
Hvala: 10
640 "Hvala" u 14 poruka
slavkan is on a distinguished roadslavkan is on a distinguished roadslavkan is on a distinguished roadslavkan is on a distinguished roadslavkan is on a distinguished roadslavkan is on a distinguished road
Default

Moze li ovako da se to skucka, nesto sam na brzinu pokusao:

Kôd:
<?php
/**
   * Export an array as downladable Excel CSV
   * @param array   $header
   * @param array   $data
   * @param string  $filename
   */
   
   
  include('include/config.php');	

  function toCSV($header, $data, $filename) {
    $sep  = "\t";
    $eol  = "\n";
    $csv  =  count($header) ? '"'. implode('"'.$sep.'"', $header).'"'.$eol : '';
    foreach($data as $line) {
      $csv .= '"'. implode('"'.$sep.'"', $line).'"'.$eol;
    }

    header('Content-Description: File Transfer');
    header('Content-Type: application/vnd.ms-excel');
    header('Content-Disposition: attachment; filename='.$filename.'.csv');
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    $csv = chr(255) . chr(254) . mb_convert_encoding($csv, 'UTF-16LE', 'UTF-8');
	header('Content-Length: '. strlen($csv));
	echo $csv;
    exit;
  }
  	
   $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";                        
		}
		
		  $filename='test';
		  toCSV($header, $data,$filename);
  
  
  ?>
slavkan je offline   Odgovorite uz citat