What are the differences between writing data to a PDF file and an XLS file in PHP?

When writing data to a PDF file in PHP, you would typically use a library like TCPDF or FPDF to generate the PDF file with the desired content and formatting. On the other hand, when writing data to an XLS file in PHP, you would use a library like PHPExcel or PhpSpreadsheet to create and populate an Excel spreadsheet with the data.

// Writing data to a PDF file using TCPDF
require_once('tcpdf/tcpdf.php');

$pdf = new TCPDF();
$pdf->AddPage();
$pdf->SetFont('helvetica', '', 12);
$pdf->Cell(0, 10, 'Hello, World!', 0, 1, 'C');
$pdf->Output('example.pdf', 'F');

// Writing data to an XLS file using PhpSpreadsheet
require 'vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello, World!');

$writer = new Xlsx($spreadsheet);
$writer->save('example.xlsx');