digitaldream / data-converter
In web application we need to convert data from one type to another. For example, array to excel file or excel file to array.
Installs: 8 859
Dependents: 4
Suggesters: 0
Security: 0
Stars: 6
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- php: ^8.2
- phpoffice/phpspreadsheet: ^1.6
README
something in web application we need to convert data from excel file to array, array to excel file and more. ##How to install
"require-dev": { "digitaldream/data-converter": "1.0.*" }
##Features
- Excel to Array and associative array (if first row marked as heading)
- Excel to json(json to excel)
- Excel to text(text to excel)
- Filter data while import from excel,json,txt,csv
- And from one format you can exchange other easily
##Uses
Example 01
$fileManager = new \DataConverter\FileExcel();
A lot of other configuration like you can define from which row you like to read and how many row it will be read. Also you can append data to file.
$config = [ 'file_path' => 'C:\Users\Tuhin\Downloads\apiv1567623ccbcfc1_570a009e10650.xlsx', 'first_row_as_headline' => true, ]; $data = $fileManager->config($config)->read()->getData(); //$data = $fileManager->config($config)->read()->toJson(); //$data = $fileManager->config($config)->read()->toText(); //$data = $fileManager->config($config)->read()->toAssoc(); print_r($data); ?>
Example 02
//Here it will process the file based on file mimetype. $fileFullPath='test.txt'; $fileManager = \DataConverter\FileManager::initByFileType($fileFullPath); if ($fileManager === FALSE) { // exit() File tye does not mathch } //here we used filter. It will take only these two columns value and other data from the souce will be ignored. $data = $fileManager->config($config)->read()->makeAssoc()->filter(['column_1','column_2])->getData();
Example 03
$fileManager = new \DataConverter\FileExcel(); $configFile = [ 'file_path' => $fullPath,// full file path where file will be saved. 'data' => $data,//data as associative array. 'mode' => 'w+'//only valid if file type is txt ]; $fileManager = $fileManager->config($configFile)->filter(['column 1','column 2'])->write(true);
More examples is in demo/exmaples.php file