Using PhpOffice\PhpSpreadsheet\IOFactory

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
athira
User
Posts: 12

Using PhpOffice\PhpSpreadsheet\IOFactory

Post by athira »

I want to read a pdf file. for that i want to use dompdf. i generated dompdf from phpmaker. Now the folder is available inside vendor/hkvstore/dompdf.
but I want to get the directory for pdf( like the excel directory given below )

<?php
require 'vendors/phpoffice/phpspreadsheet/src/phpSpreadSheet/IOFactory.php';
.....
?>

I want to write custom code for read a pdf file so need directory for read pdf.

Thanks


arbei
User
Posts: 9384

Post by arbei »

  1. You may write PDF with PhpSpreadSheet, but are you sure you can read a PDF file with it? I doubt if it can read PDF.
  2. The PhpSpreadsheet is a composer package, you don't need to require or include the file yourself. If the PhpSpreadsheet extension is enabled, you can use it directly, e.g.
    $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Pdf');

athira
User
Posts: 12

Post by athira »

<?php
// require 'vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/IOFactory.php';
include 'vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/IOFactory.php';
$inputFileName = 'demoexcel.xls';
// Read Excel file
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);

        
// Get first sheet
$sheet = $objPHPExcel->getSheet(0);
// Get highest row and column
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();

- - - - - - - - - - - - - - -
?>

in this above code error is showing like
Fatal error: Uncaught Error: Class "PHPExcel_IOFactory" not found in C:\xampp\htdocs\athira\fin_scm_dev_poc\excel_read.php:6 Stack trace: #0 {main} thrown in C:\xampp\htdocs\athira\fin_scm_dev_poc\excel_read.php on line 6
how to fix this? Thanks


arbei
User
Posts: 9384

Post by arbei »

arbei wrote:

The PhpSpreadsheet is a composer package, you don't need to require or include the file yourself. If the PhpSpreadsheet extension is enabled, you can use it directly, e.g.
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Pdf');


athira
User
Posts: 12

Post by athira »

I want to read excel file

include 'vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/IOFactory.php';
$inputFileName = 'demoexcel.xls';
// Read Excel file
$objPHPExcel = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName);

this showing error
Fatal error: Uncaught TypeError: PhpOffice\PhpSpreadsheet\IOFactory::createWriter(): Argument #1 ($spreadsheet) must be of type PhpOffice\PhpSpreadsheet\Spreadsheet, string given, called in C:\xampp\htdocs\athira\fin_scm_dev_poc\excel_read.php on line 6 and defined in C:\xampp\htdocs\athira\fin_scm_dev_poc\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\IOFactory.php:60 Stack trace: #0 C:\xampp\htdocs\athira\fin_scm_dev_poc\excel_read.php(6): PhpOffice\PhpSpreadsheet\IOFactory::createWriter('demoexcel.xls') #1 {main} thrown in C:\xampp\htdocs\athira\fin_scm_dev_poc\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\IOFactory.php on line 60


arbei
User
Posts: 9384

Post by arbei »

  1. Again: The PhpSpreadsheet is a composer package, you don't need to require or include the file yourself. If the PhpSpreadsheet extension is enabled, you can use it directly.,
  2. As the error clearly said:

PhpOffice\PhpSpreadsheet\ IOFactory::createWriter(): Argument #1 ($spreadsheet) must be of type PhpOffice\PhpSpreadsheet\Spreadsheet, string given

Review your code, check the second argument of createWriter() in your code.


Post Reply