ikinci temizlik tamamlandı
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Html;
|
||||
use Mpdf\Mpdf;
|
||||
|
||||
// Excel dosyasını yükle
|
||||
try {
|
||||
$filePath = 'storage/documents/test/test.xlsx';
|
||||
$spreadsheet = IOFactory::load($filePath);
|
||||
|
||||
|
||||
// Değiştirilecek joker alanlar ve değerleri
|
||||
$replacements = [
|
||||
'{test1}' => 'Deger1',
|
||||
'{test2}' => 'Deger2',
|
||||
'{test3}' => 'Deger3',
|
||||
// Diğer joker alanlar ve değerler buraya eklenebilir
|
||||
];
|
||||
|
||||
// Aktif çalışma sayfasını al
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
|
||||
// Tüm hücreleri döngüyle gezerek joker alanları değiştir
|
||||
foreach ($sheet->getRowIterator() as $row) {
|
||||
foreach ($row->getCellIterator() as $cell) {
|
||||
$cellValue = $cell->getValue();
|
||||
if (is_string($cellValue)) {
|
||||
foreach ($replacements as $search => $replace) {
|
||||
if (strpos($cellValue, $search) !== false) {
|
||||
$cellValue = str_replace($search, $replace, $cellValue);
|
||||
$cell->setValue($cellValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Değişiklikleri kaydetmek için yeni bir dosya oluştur
|
||||
$outputFilePath = 'storage/documents/test/output/output.xlsx';
|
||||
$htmlFilePath = 'storage/documents/test/output/output.html';
|
||||
$pdfFilePath = 'storage/documents/test/output/output.pdf';
|
||||
|
||||
// HTML yazıcı oluştur
|
||||
$htmlWriter = new Html($spreadsheet);
|
||||
$htmlWriter->save($htmlFilePath);
|
||||
$htmlContent = file_get_contents($htmlFilePath);
|
||||
|
||||
html_to_pdf($htmlFilePath, $pdfFilePath);
|
||||
|
||||
// MPDF ile PDF oluştur
|
||||
/*
|
||||
$mpdf = new Mpdf();
|
||||
$mpdf->WriteHTML($htmlContent);
|
||||
|
||||
$mpdf->Output($pdfFilePath, \Mpdf\Output\Destination::FILE);
|
||||
|
||||
// Geçici HTML dosyasını sil
|
||||
unlink($htmlFilePath);
|
||||
*/
|
||||
|
||||
echo "Dosya başarıyla PDF olarak kaydedildi: $pdfFilePath";
|
||||
|
||||
/*
|
||||
$writer = new Xlsx($spreadsheet);
|
||||
$writer->save($outputFilePath);
|
||||
|
||||
echo "Dosya başarıyla kaydedildi: $outputFilePath";
|
||||
*/
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
echo 'Hata: ' . $th->getMessage();
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user