Jump to content

php excell multiple files


Recommended Posts

Good day all.

I am looking for guidence.

I am using phpexcell to format an excell file. all working 100% What should i be looking to do when i want to edit and format multiple files in a directory. about 200 excell documents all the same and with same formatting?

Found this code for reading, but lets say row c3:i3 i want bold and size 14 in all the excell files


$path = "..."; ///the folder path
		$theFilePath = "";		
		$theFileName = glob ($path . "*.xls");
		//Read more than one file here
		for($j = 0; $j< count($theFileName); $j++) {

		$theFilePath = $theFileName[$j];
		$excel = new Spreadsheet_Excel_Reader();
		error_reporting(E_ALL ^ E_NOTICE);			
			//echo $theFileName[$j];; 
			echo "<br />";
			echo $theFilePath; 
			echo "<br />";


                          .// Do what u want display here



Link to comment
Share on other sites

hi yes - here is the code.



set_include_path(get_include_path() . PATH_SEPARATOR . './Classes/');

include 'Classes/PHPExcel/IOFactory.php';


$phpExcel = PHPExcel_IOFactory::load('/var/www/html/default/csvex/xls/aaa.xls');

function cellColor($cells,$color){
    global $objPHPExcel;

        'type' => PHPExcel_Style_Fill::FILL_SOLID,
        'startcolor' => array(
             'rgb' => $color

cellColor('B5', 'F28A8C');
cellColor('G5', 'F28A8C');
cellColor('A7:I7', 'F28A8C');
cellColor('A17:I17', 'F28A8C');
cellColor('A30:Z30', 'F28A8C');


Link to comment
Share on other sites

1. Create a function that takes the excel file as an input and performs all the operations you want to do to the excel files

2. Use a process to loop through all the excel files: scandir(), readdir(), . . . ???

3. Upon each iteration of the loop call the function in step #1 passing the current file as a parameter

Edited by Psycho
Link to comment
Share on other sites

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);

$directory = "/var/www/html/default/csvex/xls/";
$formatdirectory = "/var/www/html/default/csvex/toformat/";
$finishedformatdirectory = "/var/www/html/default/csvex/formatted/";

$files = scandir($directory, SCANDIR_SORT_DESCENDING);
$newest_file = $files[0];
echo $newest_file;
echo "<br>";
$oldfile = $directory.$newest_file;
$newfile = $formatdirectory.$newest_file;
$changedfile = $finishedformatdirectory.$newest_file;
echo $oldfile;
echo "<br>";
echo $newfile;

echo "<br>";
if( !rename($oldfile, $newfile) ) {  
    echo "File can't be moved!";  
else {  
    echo "File has been moved!";  
chmod($newfile, 755);  
//format the file

set_include_path(get_include_path() . PATH_SEPARATOR . './Classes/');

include 'PHPExcel/IOFactory.php';

$fileType = 'Excel5';
$fileName = $newfile;

// Read the file
$objReader = PHPExcel_IOFactory::createReader($fileType);
$objPHPExcel = $objReader->load($fileName);

	array('fill' 	=> array(
								'type'		=> PHPExcel_Style_Fill::FILL_SOLID,
								'color'		=> array('argb' => 'ffffffff')

// Change the file
            ->setCellValue('d1', 'booya')
            ->setCellValue('d9', 'ddddddddddddddddddd!');

// Write the file
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $fileType);



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.