Asked  7 Months ago    Answers:  5   Viewed   42 times

Is it possible to append content to an .xls file using PHP fwrite()?

When I try this using fwrite(), the resulting file causes an error message in Excel 2007.

Is there a specific separator I can use to accomplish this?

Is it possible without a third party library?



You can use the PhpSpreadsheet library, to read an existing Excel file, add new rows/columns to it, then write it back as a real Excel file.

Disclaimer: I am one of the authors of this library.

Wednesday, March 31, 2021
answered 7 Months ago

Thanks for Helping me I have found the answer for my own question.


    $rowNumber = 12;
    foreach($list as $data){
$this->excel->getActiveSheet()->setCellValue('A'.$rowNumber, $data->code_caption)
->setCellValue('B'.$rowNumber, $data->color);

    $objDrawing = new PHPExcel_Worksheet_Drawing();
    $this->excel->getActiveSheet()->setCellValue('C'.$rowNumber, '');

$this->excel->getActiveSheet()->setCellValue('D'.$rowNumber, $data->desc);
$this->excel->getActiveSheet()->setCellValue('E'.$rowNumber, $data->$d_met);
$this->excel->getActiveSheet()->setCellValue('F'.$rowNumber, $data->$w_met);
$this->excel->getActiveSheet()->setCellValue('G'.$rowNumber, $data->$h_met);
$this->excel->getActiveSheet()->setCellValue('H'.$rowNumber, $data->qty);
Wednesday, March 31, 2021
answered 7 Months ago


function addItem($serializedArray, $item)
   $a = unserialize($serializedArray);
   $a[] = $item;
   return serialize($a);
Wednesday, March 31, 2021
answered 7 Months ago

Apparently it was the application/ header that caused the problem. Setting it to octet-stream solved the issue, but then caused problems in IE8. So I used this code to totally solve the problem:

if(stristr($_SERVER['HTTP_USER_AGENT'], 'ipad') OR stristr($_SERVER['HTTP_USER_AGENT'],     'iphone') OR stristr($_SERVER['HTTP_USER_AGENT'], 'ipod')) 
  header("Content-Type: application/octet-stream"); 
  header('Content-Type: application/'); 
Wednesday, March 31, 2021
answered 7 Months ago

The error MethodNotAllowedHttpException means the route exists, but the HTTP method (GET) is wrong. You have to change it to POST:

Route::post('test/register', array('uses'=>'TestController@create'));

Also, you need to hash your passwords:

public function create()
    $user = new User;

    $user->username = Input::get('username');
    $user->email = Input::get('email');
    $user->password = Hash::make(Input::get('password'));

    return Redirect::back();

And I removed the line:

$user= Input::all();

Because in the next command you replace its contents with

$user = new User;

To debug your Input, you can, in the first line of your controller:

dd( Input::all() );

It will display all fields in the input.

Sunday, August 22, 2021
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :