Ratings | | Unique User Downloads | | Download Rankings |
Not enough user ratings | | Total: 74 | | All time: 10,213 This week: 488 |
|
Description | | Author |
This package can create an Excel file from other spreadsheet values.
It provides a script that uses Excel reader classes to parse multiple Excel spreadsheets in XLSX format to extract the values of their cells.
The script can combine the values of all the parsed spreadsheets and generates a single spreadsheet file in Excel XLSX format that merges the importance of all spreadsheets into one with a sheet with the values of other spreadsheets in multiple columns. Innovation Award
June 2023
Winner |
Excel is a popular tool for creating spreadsheets. It saves spreadsheet data in XML-based format, which usually is called XLSX.
This XML format makes it easy for PHP developers to process and create spreadsheet files in Excel XSLX format.
This package provides a script that uses an Excel parser and generator classes to show how to parse several Excel spreadsheet files and combine their values to generate a new spreadsheet that merges the importance of all spreadsheets in a single spreadsheet.
This way, other developers can learn to process multiple spreadsheets and combine them in a way that is convenient for their application purposes.
Manuel Lemos |
| |
|
|
Innovation award
Nominee: 3x
Winner: 1x |
|
Example
<?php
// Max Base
// https://github.com/BaseMax/MergeExcelFilesToOnePerColumns
// 2021-04-13, 2021-04-22
require "excel.php";
require "excel-create.php";
$authors = [];
$counts = [];
$data = [];
$prefix = "input-first/";
$prefix = "input-second/";
$files = glob($prefix . "*.xlsx");
$files_count = 0;
$count = 65;
$count = 39;
// foreach($files as $file) {
for($i=1;$i<=$count;$i++) {
$file = $prefix . $i.".xlsx";
if($file === "" || $file === "." || $file === "..") {
continue;
}
// if($files_count > 5) {
// // break;
// }
$files_count++;
// print $file."\n";
if($xlsx = SimpleXLSX::parse($file) ) {
$rows = $xlsx->rows();
// print_r($rows);
$values = [];
foreach($rows as $row) {
if(isset($row[1])) {
$values[] = $row[1];
}
else {
$values[] = "";
}
}
// print_r($values);
$counts[] = (int) count($values);
$authors[] = $values;
// exit();
// $values = [];
// foreach($rows as $row) {
// print_r($row);
// if(isset($row[0], $row[1]) && $row[0] !== "" && $row[1] !== "") {
// $row[1] = $row[1];
// $values[] = $row[1];
// }
// }
// // print_r($values);
// $counts[] = (int) count($values);
// $authors[] = $values;
// exit();
} else {
echo SimpleXLSX::parseError();
}
}
// print_r($authors);
$m = max($counts);
// print $m."\n";
// exit();
$c = count($authors);
// print count($authors[0])."\n";
// exit();
for($i=1;$i<=$m;$i++) {
$data[$i-1] = [];
}
for($i=1;$i<=$m;$i++) {
for($j=1;$j<=$c;$j++) {
$data[$i-1][$j-1] = "";
if(isset($authors[$j-1][$i-1])) {
$data[$i-1][$j-1] = $authors[$j-1][$i-1];
}
}
}
// print_r($data);
// exit();
// for($i=1;$i<=$c;$i++) {
// for($j=1;$j<=$m;$j++) {
// if(isset($authors[$i-1][$j])) {
// print $authors[$i-1][$j];
// }
// print "\t";
// }
// print "\n";
// }
// exit();
// for($j=0;$j<500;$j++) {
// $has = false;
// for($i=0;$i<$files_count;$i++) {
// print $i."\t";
// if(isset($authors[$i][$j])) {
// $authors[$i][$j] = trim($authors[$i][$j]);
// if($authors[$i][$j] !== "") {
// $has = true;
// print $authors[$i][$j];
// print "\t";
// }
// }
// }
// if($has === true) {
// print "\n";
// }
// }
$xlsx = SimpleXLSXGen::fromArray($data);
$xlsx->saveAs('res.xlsx');
|
Details
Merge Excel Files to single excel file per columns
Using
Set your directory name at https://github.com/BaseMax/MergeExcelFilesToOnePerColumns/blob/main/parser.php#L14, and number of files at https://github.com/BaseMax/MergeExcelFilesToOnePerColumns/blob/main/parser.php#L20.
Your directory should look like: 1.xlsx, 2.xlsx, 3.xlsx, 4.xlsx, etc....
Now convert all excel files to a single file by running:
php parser.php
Next open res.xlsx
file in your excel or libreoffice...
© Copyright 2021 Max Base
|
Applications that use this package |
|
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.