-
Notifications
You must be signed in to change notification settings - Fork 0
/
XML.php
executable file
·86 lines (77 loc) · 2.8 KB
/
XML.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
* Bioversity AGROVOC Indexing
*
* PHP Version 7.2.11
*
* @copyright
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License, version 3
* @link https://github.com/gubi/bioversity_agrovoc-indexing
*/
/**
* A script for manage XML file and prepare data for Dataverse
*
* @package Bioversity AGROVOC Indexing
* @author Alessandro Gubitosi <[email protected]>
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License, version 3
* @link https://github.com/gubi/bioversity_agrovoc-indexing
*/
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\IOFactory;
class XML {
public static $filename = "";
public static $worksheet;
public static $spreadsheet;
/**
* Initialize the XML file
*/
public static function init() {
self::$spreadsheet = new Spreadsheet();
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
self::$spreadsheet = $reader->load(self::$filename);
self::$worksheet = self::$spreadsheet->getActiveSheet();
}
/**
* Get the Excel column name
* @example "A1"
*
* @param integer $col The target column
* @return string The column name
*/
public static function get_excel_column($col) {
return self::$worksheet->getCellByColumnAndRow($col, 1)->getCoordinate();
}
/**
* Get the Excel column title
*
* @param integer $col The target column
* @return string The column name
*/
public static function get_column_title($col) {
return self::$worksheet->getCellByColumnAndRow($col, 1)->getValue();
}
/**
* Get a single cell value
*
* @param integer $row The target row
* @param integer $col The target column
* @return string The cell value
*/
public static function get_cell_value($row, $col) {
return self::$worksheet->getCellByColumnAndRow($col, $row)->getValue();
}
/**
* Determine if a given row is visible
*
* @param integer $row The target row
* @return boolean
*/
public static function is_visible_row($row) {
if(is_integer($row)) {
return self::$spreadsheet->getActiveSheet()->getRowDimension($row)->getVisible();
} else {
return self::$spreadsheet->getActiveSheet()->getRowDimension($row->getRowIndex())->getVisible();
}
}
}
?>