简体   繁体   中英

php-excel-reader not displaying format of empty cells

I'm working on a little app that takes Excel spreadsheets that display tournament brackets, and then output the excel data and formatting into xml. I'm using Spreadsheet_Excel_Reader ( https://code.google.com/archive/p/php-excel-reader/ ) to retrieve the data from the tournament bracket spreadsheets. The only problem is that any cell will no value will not be put in the Spreadsheet_Excel_Reader->sheets[0]['cells'] array, thus causing the table cell borders to not output. It appears that if I put a space in each cell that I want display, it works fine, but that seems like a pretty hackey way of doing it. Does anyone if there is a better way to output the formatting of a blank cell using the Spreadsheet_Excel_Reader?

I found this question after having the same problem (a spreadsheet row with 5 columns, 2 of them blank, are shown as an array of 3 items, omitting the 2 empty cells).

It took longer than I wanted it to, but I think I figured it out. When you dump your row data, check out the indexes.

array(5) {
  ["maxrow"]=>
  int(0)
  ["maxcol"]=>
  int(0)
  ["numRows"]=>
  int(2)
  ["numCols"]=>
  int(3)
  ["cells"]=>
  array(2) {
    [1]=>
    array(2) {
      [1]=>
      string(4) "test"
      [2]=>
      string(3) "xls"
    }
    [2]=>
    array(2) {
      [1]=>
      string(5) "empty"
      [3]=>
      string(4) "test"
    }
  }
}

In my case, I have an empty cell in the second row, between "empty" and "test", and I can see that "test" as the index '3'.

What you (and I) need to do is, instead of using foreach(), be sure to iterate over each expected index using for() or foreach(range()) ending at numCols.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM