PHP code example of pausermake / laravel-xlswriter-fix

1. Go to this page and download the library: Download pausermake/laravel-xlswriter-fix library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pausermake / laravel-xlswriter-fix example snippets


'providers' => [

 /* * Laravel Framework Service Providers... */ ... \Lysice\XlsWriter\XlsWriterServiceProvider::class ],
 

 php artisan vendor:publish --provider="Lysice\XlsWriter\XlsWriterServiceProvider"
 

 php artisan xls:status
 

 php artisan xls:export XXXXExport array
 

 php artisan xls:export XXXXExport array
 

 php artisan xls:export XXXXExport query
 

 php artisan xls:export XXXXExport collection



namespace App\Exports;

use Lysice\XlsWriter\Interfaces\FromArray;

class UserExport implements FromArray
{
 /** 
  * @return array */ 
  public function array() : array 
  { 
    return [ ['哈哈', 'aaa'],
         ['哈哈', 'aaa'],
         ['哈哈', 'aaa'],
         ['哈哈', 'aaa']
         ]; 
  }
 /** 
   * @return array 
   */ 
 public function headers() : array {
     return []; 
 }
}

/**
 * @return array 
 */ 
 public function headers() : array {
     return []; 
 }
 

 Route::get('xls', function() {
     return Excel::download((new \App\Exports\UserExport())); 
 });
 

Route::get('xls', function() {
 // 直接下载
 return Excel::download((new \App\Exports\UserExport()), 'test');});

Route::get('xls', function() {
 return Excel::download((new \App\Exports\UserExport()), 'test', \Lysice\XlsWriter\Excel::TYPE_CSV);
 });

Route::get('xls', function() {
 return Excel::download((new \App\Exports\UserExport()), 'test', \Lysice\XlsWriter\Excel::TYPE_CSV, ['a' => b]);});

 /** 
   * @return array * @throws \Lysice\XlsWriter\Exceptions\FormatParamErrorException 
   */ 
   public function defaultFormats(): array {
   	$formatOne = DefaultFormat::create()
		->border(12)
		->background(Constants::COLOR_MAGENTA); 
		$formatTwo = DefaultFormat::create()
		->underline( Constants::UNDERLINE_SINGLE)
		->wrap(); 
	return [$formatOne, $formatTwo]; 
 }
 

 public function zoom() { 
 	return 300; 
 }
 

 public function gridLine() {
 	return Constants::GRIDLINES_HIDE_ALL; 
 }

/**
 * @return array * @throws \Lysice\XlsWriter\Exceptions\FormatParamErrorException */ 
 public function columnFormats() {
	$formatOne = ColumnFormat::create()
		->setCellType(CellConstants::CELL_TYPE_TEXT)
		->border(12) 
		->background(\Lysice\XlsWriter\Supports\Constants::COLOR_MAGENTA); 
	$formatTwo = ColumnFormat::create() 
		->setOptions(['dateFormat' => "mm/dd/yy"])
		->setCellType(CellConstants::CELL_TYPE_DATE) 
		->underline( \Lysice\XlsWriter\Supports\Constants::UNDERLINE_SINGLE) 
		->wrap();
 	$formatThree = ColumnFormat::create() 
		->setCellType(CellConstants::CELL_TYPE_FORMULA) 
		->italic() 
		->fontSize(12);
	$formatFour = ColumnFormat::create() 
		->setOptions([ 'widthScale' => 1.1, 'heightScale' => 1.1 ])
		->setCellType(CellConstants::CELL_TYPE_IMAGE) 
		->border(1); 
	$formatFive = ColumnFormat::create() 
 	->setCellType(CellConstants::CELL_TYPE_URL) 
 	->border(1); 
 	return [$formatOne, $formatTwo, $formatThree, $formatFour, $formatFive]; 
 }