-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-upload-page.php
57 lines (45 loc) · 1.53 KB
/
test-upload-page.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?
defined('ABSPATH') OR exit;
/**
* Template Name: Test Upload Page
* Description: Test new applications for the site.
*
* @package WordPress
* @subpackage WP-Skeleton
*/
get_header();
get_template_part( 'sub-header', 'index' ); //the header stuffs
get_template_part( 'menu', 'index' ); //the menu + logo/site title
//include autoloader
require 'includes/phpoffice/vendor/autoload.php';
//load dependencies
use \PhpOffice\PhpSpreadsheet\Reader\Xlsx;
use \PhpOffice\PhpSpreadsheet\Writer\Csv;
?>
<div class="super-container events-holder">
<div class="events-header">
<p>PHP Spreadsheet Test</p>
<?
$upload_dir = wp_upload_dir();
$file = $upload_dir['basedir'].'/hcc_schedules_st314.xlsx';
var_viewer($file);
$reader = new Xlsx();
$spreadsheet = $reader->load($file);
$loadedSheetNames = $spreadsheet->getSheetNames();
$objWriter = new Csv($spreadsheet);
foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
$objWriter->setSheetIndex($sheetIndex);
$new_path = $upload_dir['basedir'].'/'.$loadedSheetName.'.csv';
$objWriter->save($new_path);
}
$csvData = file_get_contents($new_path);
$lines = explode(PHP_EOL, $csvData);
$array = array();
foreach ($lines as $line) {
$array[] = str_getcsv($line);
}
var_viewer($array);
?>
</div>
</div>
<? get_footer(); ?>