Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export xls file not readable for import time in php

I am using below code for export xls file abd it is working file but my issue is when i try to read file using require "XLS/Excel/reader.php" library it return error "file is not redable." When i save as export xls file and try to import it working.

function xlsBOF() {
  echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
}
function xlsEOF() {
  echo pack("ss", 0x0A, 0x00);
}
function xlsWriteNumber($Row, $Col, $Value) {
  echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
  echo pack("d", $Value);
}
function xlsWriteLabel($Row, $Col, $Value) {
  $L = strlen($Value);
  echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
  echo $Value;
} 
// prepare headers information
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/xls");
header("Content-Disposition: attachment; filename=test.xls");
header("Content-Transfer-Encoding: binary");
header("Pragma: no-cache");
header("Expires: 0");
// start exporting
xlsBOF();
xlsWriteLabel(0, 0, "id");
xlsWriteLabel(0, 1, "name");
xlsWriteLabel(0, 2, "email");
xlsWriteNumber(1, 0, 230);
xlsWriteLabel(1, 1, "John");
xlsWriteLabel(1, 2, "[email protected]");
xlsWriteNumber(2, 0, 350);
xlsWriteLabel(2, 1, "Mark");
xlsWriteLabel(2, 2, "[email protected]");
xlsEOF();
like image 640
Mukesh Avatar asked Oct 19 '22 05:10

Mukesh


1 Answers

use http://phpexcel.codeplex.com/ library for export it will working fine.

$objPHPExcel = new PHPExcel(); 
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', 'Hello'); 
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('B2', 'world!'); 
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('C1', 'Hello'); 
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('D2', 'world!'); 
like image 50
Bharat Bhola Avatar answered Oct 30 '22 23:10

Bharat Bhola