Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once 'simple_html_dom.php';
- require_once 'PHPExcel.php';
- $url = 'https://www.duurzaamloket.nl/SolKey_X014/index.php?SchemeNo=0&Offset=1&SearchText=&PageCnt=500';
- // Load the HTML content from the URL
- $html = file_get_html($url);
- // Find the table and extract the data
- $table = $html->find('table.LicDetails', 0);
- $headers = array();
- $rows = array();
- foreach ($table->find('tr') as $row) {
- $cols = array();
- foreach ($row->find('th,td') as $col) {
- $cols[] = $col->plaintext;
- }
- if (empty($headers)) {
- $headers = $cols;
- } else {
- $rows[] = $cols;
- }
- }
- // Create a new Excel workbook and write the data
- $wb = new PHPExcel();
- $ws = $wb->getActiveSheet();
- // Write headers to the first row
- foreach ($headers as $col_num => $header) {
- $ws->setCellValueByColumnAndRow($col_num, 1, $header);
- }
- // Write table data to the worksheet
- foreach ($rows as $row_num => $row) {
- foreach ($row as $col_num => $col) {
- $ws->setCellValueByColumnAndRow($col_num, $row_num + 2, $col);
- }
- }
- // Save the workbook to an Excel file
- $objWriter = PHPExcel_IOFactory::createWriter($wb, 'Excel2007');
- $objWriter->save('solkey_data.xlsx');
- echo 'Data saved to solkey_data.xlsx';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement