What you need to add pametra to Cyrillic to save excel file?

<?php include("config.php"); global $connection; $ts = date('mdY-His'); $sql = "SELECT * FROM price"; $result = mysqli_query($connection, $sql) or die(mysqli_error()); header("Content-Type: application/xls"); header("Content-Disposition: attachment; filename=importdetails-".$ts.".xls"); header("Pragma: no-cache"); header("Expires: 0"); header("Content-Transfer-Encoding: binary "); // here is the formatting for Excel $sep = "\t"; //tabbed character // printing the column names /* for ($i = 0; $i < mysqli_num_fields($result); $i++) { echo mysqli_fetch_field($result,$i) . "\t"; }*/ print("\n"); ?> <?php while($row = mysqli_fetch_row($result)) { $schema_insert = ""; for($j = 0; $j < mysqli_num_fields($result); $j++) { if(!isset($row[$j])) $schema_insert .= "NULL".$sep; elseif ($row[$j] != "") $schema_insert .= "$row[$j]".$sep; else $schema_insert .= "".$sep; } $schema_insert = str_replace($sep."$", "", $schema_insert); $schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert); $schema_insert .= "\t"; print(trim($schema_insert)); print "\n"; } ?> 
  • It seems to me, or do you really output the data as plain-text, but for some reason call it application/xls ? But in general, for Excel-delimited text files, it adequately eats the usual Windows encoding cp1251. - Nofate
  • and where to write this encoding? - LLIAKAJI

1 answer 1

 $mysqli->set_charset("utf8"); 

Specify in the header the output encoding charset=utf-8 .

xls has a different format, not?

CSV is usually generated for excel.