@@ -61,7 +61,12 @@ public function getCell($row_num, $col_num) {
6161 if (!$ this ->isCellExists ($ row_num , $ col_num )) {
6262 throw new \Exception ('Cell ' .$ row_num .', ' .$ col_num .' doesn \'t exist ' , SimpleExcelException::CELL_NOT_FOUND );
6363 }
64- return $ this ->table_arr ['table_contents ' ][$ row_num -1 ]['row_contents ' ][$ col_num -1 ]['value ' ];
64+ if (is_array ($ this ->table_arr ['table_contents ' ][$ row_num -1 ]['row_contents ' ])){
65+ if (array_key_exists ($ col_num -1 , $ this ->table_arr ['table_contents ' ][$ row_num -1 ]['row_contents ' ])){
66+ return $ this ->table_arr ['table_contents ' ][$ row_num -1 ]['row_contents ' ][$ col_num -1 ]['value ' ];
67+ }
68+ }
69+ return "" ;
6570 }
6671
6772 /**
@@ -99,10 +104,12 @@ public function getColumn($col_num, $val_only = TRUE) {
99104 foreach ($ this ->table_arr ['table_contents ' ] as $ row ) {
100105 if ($ row ['row_contents ' ]) {
101106 if (!$ val_only ) {
102- array_push ($ col_arr ,$ row ['row_contents ' ][$ col_num -1 ]);
107+ array_push ($ col_arr , $ row ['row_contents ' ][$ col_num -1 ]);
103108 } else {
104- array_push ($ col_arr ,$ row ['row_contents ' ][$ col_num -1 ]['value ' ]);
109+ array_push ($ col_arr , $ row ['row_contents ' ][$ col_num -1 ]['value ' ]);
105110 }
111+ } else {
112+ array_push ($ col_arr , "" );
106113 }
107114 }
108115
@@ -113,14 +120,29 @@ public function getColumn($col_num, $val_only = TRUE) {
113120 /**
114121 * Get data of all cells as an array
115122 *
123+ * @param bool $val_only Returns (value only | complete data) for every cell, default to TRUE
116124 * @return array
117125 * @throws Exception If the field is not set.
118126 */
119- public function getField () {
127+ public function getField ($ val_only = TRUE ) {
120128 if (!$ this ->isFieldExists ()) {
121129 throw new \Exception ('Field is not set ' , SimpleExcelException::FIELD_NOT_FOUND );
122130 }
123- return $ this ->table_arr ;
131+ if ($ val_only ){
132+ $ field = array ();
133+ foreach ($ this ->table_arr ['table_contents ' ] as $ row ){
134+ $ cells = array ();
135+ if ($ row ['row_contents ' ]){
136+ foreach ($ row ['row_contents ' ] as $ cell ){
137+ array_push ($ cells , $ cell ['value ' ]);
138+ }
139+ }
140+ array_push ($ field , $ cells );
141+ }
142+ return $ field ;
143+ } else {
144+ return $ this ->table_arr ;
145+ }
124146 }
125147
126148 /**
@@ -159,7 +181,7 @@ public function getRow($row_num, $val_only = TRUE) {
159181 * @return bool
160182 */
161183 public function isCellExists ($ row_num , $ col_num ){
162- return isset ( $ this ->table_arr [ ' table_contents ' ][ $ row_num- 1 ][ ' row_contents ' ][ $ col_num- 1 ] );
184+ return $ this ->isRowExists ( $ row_num) && $ this -> isColumnExists ( $ col_num );
163185 }
164186
165187 /**
@@ -169,7 +191,15 @@ public function isCellExists($row_num, $col_num){
169191 * @return bool
170192 */
171193 public function isColumnExists ($ col_num ){
172- return isset ($ this ->table_arr ['table_contents ' ]);
194+ $ exist = false ;
195+ foreach ($ this ->table_arr ['table_contents ' ] as $ row ){
196+ if (is_array ($ row ['row_contents ' ])){
197+ if (array_key_exists ($ col_num -1 , $ row ['row_contents ' ])){
198+ $ exist = true ;
199+ }
200+ }
201+ }
202+ return $ exist ;
173203 }
174204
175205 /**
@@ -179,7 +209,7 @@ public function isColumnExists($col_num){
179209 * @return bool
180210 */
181211 public function isRowExists ($ row_num ){
182- return isset ( $ this ->table_arr ['table_contents ' ][ $ row_num - 1 ][ ' row_contents ' ]);
212+ return array_key_exists ( $ row_num - 1 , $ this ->table_arr ['table_contents ' ]);
183213 }
184214
185215 /**
0 commit comments