PHPExcel - reading 4 CSV files in one book with 4 lists

I need to collect 4 CSV files into one Excel workbook using PHPExcel.

Working with a single CSV file and mono-spreadsheet works fine. Using multiple CSVs, I cannot get each CSV file on a separate sheet.

How can I achieve this with PHPExcel?

+4
source share
2 answers

Here is an example of this in the Documentation / Examples / Readers directory in the SVN repository for PHPEXcel: Example # 13

include 'PHPExcel/IOFactory.php'; $inputFileType = 'CSV'; $inputFileNames = array('./example1.csv','./example2.csv','./example3.csv','./example4.csv'); $objReader = PHPExcel_IOFactory::createReader($inputFileType); $inputFileName = array_shift($inputFileNames); $objPHPExcel = $objReader->load($inputFileName); $objPHPExcel->getActiveSheet()->setTitle(pathinfo($inputFileName,PATHINFO_BASENAME)); foreach($inputFileNames as $sheet => $inputFileName) { $objReader->setSheetIndex($sheet+1); $objReader->loadIntoExisting($inputFileName,$objPHPExcel); $objPHPExcel->getActiveSheet()->setTitle(pathinfo($inputFileName,PATHINFO_BASENAME)); } $loadedSheetNames = $objPHPExcel->getSheetNames(); foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) { $objPHPExcel->setActiveSheetIndexByName($loadedSheetName); echo $loadedSheetName,PHP_EOL; $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); var_dump($sheetData); echo PHP_EOL; } 
+4
source

You did not indicate exactly where the problem is ...
For multiple Excel Excel files, follow these steps:

  • Download CSV File
  • Create a new sheet
  • Record CSV on a new worksheet
  • Go to 1

From the docs:
If you need to create more worksheets in a book, here's how:

 $objWorksheet1 = $objPHPExcel->createSheet(); $objWorksheet1->setTitle('Another sheet'); 

To install an active worksheet:

 $objWorksheet1->setActiveSheetIndex($index); 
0
source

Source: https://habr.com/ru/post/1383585/


All Articles