Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: Mozart
- * Date: 28.11.2014
- * Time: 0:18
- */
- require_once dirname(__FILE__) . '/../Classes/PHPExcel.php';
- //$template = new PHPExcel_Template("1.xlsx");
- //$template->setValue('111', '33333');
- //$template->setValue('222', '44444');
- //$template->saveAs("test.xlsx");
- $variables = array(
- 'value1' => 'foo',
- 'value2' => 'bar',
- 'value3' => 'hoge',
- );
- $templateFile = '1.xlsx';
- $documentFile = 'test.xlsx';
- copy($templateFile, $documentFile);
- $zipArchive = new PHPExcel_Shared_ZipArchive();
- $zipArchive->open($documentFile);
- $sharedStrings = $zipArchive->getFromName('xl/sharedStrings.xml');
- foreach ($variables as $name => $value) {
- $sharedStrings = preg_replace('/(' . preg_quote('${' . $name . '}') . ')/', $value, $sharedStrings);
- }
- $zipArchive->addFromString('xl/sharedStrings.xml', $sharedStrings);
- $zipArchive->close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement