3 namespace SimpleExcel\Parser;
32 foreach ($attrs_obj as $attrs) {
33 $attrs = (array) $attrs;
34 foreach ($attrs as $attr) {
35 $attr_keys = array_keys($attr);
36 $attrs_arr[$attr_keys[0]] = $attr[$attr_keys[0]];
51 public function getCell($row_num, $col_num, $val_only =
true) {
56 if(is_array($this->table_arr[
'table_contents'][$row_num-1][
'row_contents'])){
57 if(array_key_exists($col_num-1, $this->table_arr[
'table_contents'][$row_num-1][
'row_contents'])){
58 $cell = $this->table_arr[
'table_contents'][$row_num-1][
'row_contents'][$col_num-1];
62 return $cell[
'value'];
77 public function getColumn($col_num, $val_only = TRUE) {
85 foreach ($this->table_arr[
'table_contents'] as
$row) {
86 if ($row[
'row_contents']) {
88 array_push($col_arr, $row[
'row_contents'][$col_num-1]);
90 array_push($col_arr, $row[
'row_contents'][$col_num-1][
'value']);
93 array_push($col_arr,
"");
114 foreach($this->table_arr[
'table_contents'] as
$row){
116 if($row[
'row_contents']){
117 foreach($row[
'row_contents'] as $cell){
118 array_push($cells, $cell[
'value']);
121 array_push($field, $cells);
137 public function getRow($row_num, $val_only = TRUE) {
141 $row = $this->table_arr[
'table_contents'][$row_num-1][
'row_contents'];
145 foreach (
$row as $cell) {
147 array_push($row_arr, $cell);
149 array_push($row_arr, $cell[
'value']);
165 foreach($this->table_arr[
'table_contents'] as
$row){
166 if(is_array($row[
'row_contents'])){
167 if(array_key_exists($col_num-1, $row[
'row_contents'])){
182 return array_key_exists($row_num-1, $this->table_arr[
'table_contents']);
195 $xmlns = $xml->getDocNamespaces();
198 if ($xmlns[
'ss'] !=
'urn:schemas-microsoft-com:office:spreadsheet') {
203 $doc_props = (array)$xml->DocumentProperties;
204 $this->table_arr[
'doc_props'] = $doc_props;
206 $rows = $xml->Worksheet->Table->Row;
208 $this->table_arr = array(
209 'doc_props' => array(),
210 'table_contents' => array()
214 foreach ($rows as
$row) {
217 $row_index = $row->xpath(
'@ss:Index');
220 if (count($row_index) > 0) {
221 $gap = $row_index[0]-count($this->table_arr[
'table_contents']);
222 for($i = 1; $i < $gap; $i++){
223 array_push($this->table_arr[
'table_contents'], array(
224 'row_num' => $row_num,
225 'row_contents' =>
'',
233 $row_attrs = $row->xpath(
'@ss:*');
239 foreach ($cells as $cell) {
242 $cell_index = $cell->xpath(
'@ss:Index');
245 if (count($cell_index) > 0) {
246 $gap = $cell_index[0]-count($row_arr);
247 for ($i = 1; $i < $gap; $i++) {
248 array_push ($row_arr, array(
249 'row_num' => $row_num,
250 'col_num' => $col_num,
263 $data_attrs = $cell->Data->xpath(
'@ss:*');
265 $cell_datatype = $data_attrs_arr[
'Type'];
268 $cell_value = (string) $cell->Data;
271 $cell_value = filter_var($cell_value, FILTER_SANITIZE_SPECIAL_CHARS);
274 array_push($row_arr, array(
275 'row_num' => $row_num,
276 'col_num' => $col_num,
277 'datatype' => $cell_datatype,
278 'value' => $cell_value,
286 array_push($this->table_arr[
'table_contents'], array(
287 'row_num' => $row_num,
288 'row_contents' => $row_arr,
309 return $this->
parseDOM(simplexml_load_file($file_path));
319 return $this->
parseDOM(simplexml_load_string($str));