-1

here is my code..but excel sheet is unexpected.here is my excel file

        mysql_connect("localhost", "root", "");
        mysql_select_db("personel");

        header( "Content-Type: application/vnd.ms-excel" ); 
        header( "Content-disposition: attachment; filename=TumPersonel.xls" );
        header("CONTENT-TYPE: text/html; charset=utf-8"); 

        if(isset($_POST["aktar"])){
        echo mb_convert_encoding('Personel Adı Soyadı'."\t". 'Firma Adı'."\t".'İstihdamı'."\t".'Fiili Çalıştığı Kuruluş'."\t".'Fiili Ünvanı'."\t". 'Kadrosunun Bulunduğu Kuruluş'."\t". 'Kadro Ünvanı'."\t". 'İşe Başladığı Tarih'."\t".'Sicil No'."\t". 'Mezuniyet'."\t". 'Mezun Olduğu Okul'."\t". 'Mezun Olduğu Bölüm/Branş'."\t".'TC Kimlik No'."\t".'Cinsiyet'."\t".'Doğum Tarihi'."\t".'Doğum Yeri'."\t".'Baba Adı'."\t".'Anne Adı'."\t". 'Medeni Hali'."\t". 'Çocuk Sayısı'."\t". 'Kan Grubu'."\t". 'E-Mail'."\t". 'Telefon'."\t". 'Adres'."\t". 'İlçe'."\t". "\n","windows-1254","utf-8");

        $sql=mysql_query("SELECT * FROM workers ORDER by ID");

        while($row=mysql_fetch_assoc($sql)){
            echo mb_convert_encoding( $row['username']. "\t" .$row['firma']. "\t" .$row['istihdam']. "\t" .$row['firm']. "\t" .$row['funvan']. "\t". $row['kkurulus']. "\t" .$row['kunvan']. "\t" .$row['tarih']. "\t" .$row['sicilno']. "\t" .$row['mezun']. "\t" .$row['mezuno']. "\t" .$row['mezunb']. "\t" .$row['tcno']. "\t" .$row['cins']. "\t" .$row['dtarih']. "\t" .$row['dyer']. "\t" .$row['badi']. "\t" .$row['aadi']. "\t" .$row['medeni']. "\t" .$row['csayisi']. "\t" .$row['kgrup']. "\t" .$row['email']. "\t" .$row['tel']. "\t" .$row['adres']. "\t" .$row['ilce']."\n","windows-1254","utf-8");
            }
        }
2
  • 1
    You're sending the mimetype for an Excel file, and following it with tab-separated values. This won't work. If you want to create an Excel file look at PHPExcel, or send comma-separated values. Commented Nov 18, 2013 at 7:25
  • stackoverflow.com/questions/3163559/… Commented Nov 18, 2013 at 7:25

2 Answers 2

3

try out with

$filename = d:/download/excelFileName.xls //filename with folder path where you want to save excel file

$getExcelData = 'SELECT column1, column2, column3 from workers INTO OUTFILE "'.$filename.'" FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY "\n"' //mysql query;

$getResult = mysql_query($getExcelData _csv); //after execution of this query your excel file will created on d:/dowload folder by name excelFileName.xls
its work for me
refer http://dev.mysql.com/doc/refman/5.1/en/load-data.html

Sign up to request clarification or add additional context in comments.

7 Comments

i couldn't integrated it to my code..sorry i'm bad on that
if your problem will not solve then reply i ll try my best
i have updated my answer, have a look
thanks for your answer.i'm gonna try then turn back to you
i have to use isset function for call excel but i couldn't again :((
|
1

Can you try to remove this line:

header("CONTENT-TYPE: text/html; charset=utf-8");

1 Comment

It is not relevant here.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.