Copy Workseet

Topics: User Forum
Oct 29, 2010 at 3:40 PM

Hi,

i'm using PHP 5.3.3

Excel 2007 on Windows XP

PHPExcel 1.7.4

I Have a script like this

<?PHP
$hebdo = "./xls/Checklist_hebdomadaire_Courbevoie_V1.xlsx";
$mensuel = "./xls/Checklist_Mensuelle_Courbevoie.xlsx";
$journaliere  "./xls/Checklist_quotidienne_Techniciens_Courbevoie_V4.xlsx";


require_once './Classes/PHPExcel.php';
require_once './Classes/PHPExcel/Reader/Excel2007.php';
require_once './Classes/PHPExcel/Writer/Excel2007.php';

...


$objetmensuel = new PHPExcel_Reader_Excel2007();
$excelmensuel = $objetmensuel->load($mensuel);
$objethebdo = new PHPExcel_Reader_Excel2007();
$excelhebdo = $objethebdo->load($hebdo);
$objetjournaliere = new PHPExcel_Reader_Excel2007();
$exceljournaliere = $objetjournaliere->load($journaliere);

$sheet1 = $exceljournaliere->getSheet(0);
$sheet2 = $sheet1->copy();
$sheet2->setTitle($date_shit." Matin");
echo "$date_affiche";
$sheet2->setCellValue('A1', "Date : ".$date_affiche."                                                                       Heure :");


...

$save = new PHPExcel_Writer_Excel2007($writer);
$save->save('Exemple_gg.xlsx');

?>

i manage to have all the sheet i want, but it's only copy the data of the cell and not the styles of the cell.

So could you tell me what i'm doing wrong ?

Thanks

 

Coordinator
Nov 1, 2010 at 10:29 PM

Without running tests, I can't tell you what's wrong: the copy() method should create a new worksheet with identical styling and data... however, you're copying between workbooks, and much of the styling is held against the workbook, not against the worksheet. If you're trying to copy sheets between workbooks, look at using the $PHPExcelObject addExternalSheet() method.