We have saved Hindi & English data in our database table column by using PHP/Mysql. Now the same data should be exported in correct form: Hindi & English. English content is correctly written in xls file; but hindi content is not properly exported. Following is my code.
function xlsBOF() {
echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
return;
}
function xlsEOF() {
echo pack("ss", 0x0A, 0x00);
return;
}
function xlsWriteNumber($Row, $Col, $Value) {
echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
echo pack("d", $Value);
return;
}
function xlsWriteLabel($Row, $Col, $Value) {
$L = strlen($Value);
echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
echo $Value;
return;
}
header("Content-Type: application/vnd.ms-excel; charset=UTF-8");
header("Pragma: public");
header("Expires: 0");
header('Content-Encoding: UTF-8');
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment;filename=Report.xls");
header("Content-Transfer-Encoding: binary");
xlsBOF();
$columns = array('Col1', 'Col2', 'Col3');
for ($i = 0; $i < count($columns); $i++) {
xlsWriteLabel(0, $i, $columns[$i]);
}
$xlsRow = 1;
// $inspectionsxls_array: Array contains data Hindi/Column.
if (!empty($inspectionsxls_array)) {
foreach ($inspectionsxls_array as $list) {
for ($j = 0; $j < count($columns); $j++) {
xlsWriteLabel($xlsRow, $j, $list[$j]);
}
$xlsRow++;
}
}
xlsEOF();
exit();