~fabiocbalbuquerque/sahana-agasti/web-services

« back to all changes in this revision

Viewing changes to apps/frontend/lib/util/phpExcelReader/spreadsheetExcelReader.class.php

  • Committer: Clayton Kramer
  • Date: 2011-06-02 20:32:55 UTC
  • mto: (1.26.1 push-trunk) (7.1.1 mayon)
  • mto: This revision was merged to the branch mainline in revision 17.
  • Revision ID: clayton.kramer@mail.cuny.edu-20110602203255-jibrhvvu4193e0sa
Staff import working. Still needs to be hooked to indexer.

Show diffs side-by-side

added added

removed removed

Lines of Context:
112
112
  function val($row, $col, $sheet=0)
113
113
  {
114
114
    $col = $this->getCol($col);
115
 
    if (array_key_exists($row, $this->sheets[$sheet]['cells']) && array_key_exists($col, $this->sheets[$sheet]['cells'][$row])) {
 
115
    if (array_key_exists($row, $this->sheets[$sheet]['cells']) && array_key_exists($col,
 
116
                                                                                   $this->sheets[$sheet]['cells'][$row])) {
116
117
      return $this->sheets[$sheet]['cells'][$row][$col];
117
118
    }
118
119
    return "";
838
839
    $pos = 0;
839
840
    $data = $this->data;
840
841
 
841
 
    $code = v($data, $pos);
842
 
    $length = v($data, $pos + 2);
843
 
    $version = v($data, $pos + 4);
844
 
    $substreamType = v($data, $pos + 6);
 
842
    $code = parent::v($data, $pos);
 
843
    $length = parent::v($data, $pos + 2);
 
844
    $version = parent::v($data, $pos + 4);
 
845
    $substreamType = parent::v($data, $pos + 6);
845
846
 
846
847
    $this->version = $version;
847
848
 
856
857
 
857
858
    $pos += $length + 4;
858
859
 
859
 
    $code = v($data, $pos);
860
 
    $length = v($data, $pos + 2);
 
860
    $code = parent::v($data, $pos);
 
861
    $length = parent::v($data, $pos + 2);
861
862
 
862
863
    while ($code != SPREADSHEET_EXCEL_READER_TYPE_EOF) {
863
864
      switch ($code) {
869
870
          for ($i = 0; $i < $uniqueStrings; $i++) {
870
871
            // Read in the number of characters
871
872
            if ($spos == $limitpos) {
872
 
              $opcode = v($data, $spos);
873
 
              $conlength = v($data, $spos + 2);
 
873
              $opcode = parent::v($data, $spos);
 
874
              $conlength = parent::v($data, $spos + 2);
874
875
              if ($opcode != 0x3c) {
875
876
                return -1;
876
877
              }
889
890
 
890
891
            if ($richString) {
891
892
              // Read in the crun
892
 
              $formattingRuns = v($data, $spos);
 
893
              $formattingRuns = parent::v($data, $spos);
893
894
              $spos += 2;
894
895
            }
895
896
 
911
912
              $spos = $limitpos;
912
913
 
913
914
              while ($charsLeft > 0) {
914
 
                $opcode = v($data, $spos);
915
 
                $conlength = v($data, $spos + 2);
 
915
                $opcode = parent::v($data, $spos);
 
916
                $conlength = parent::v($data, $spos + 2);
916
917
                if ($opcode != 0x3c) {
917
918
                  return -1;
918
919
                }
972
973
        case SPREADSHEET_EXCEL_READER_TYPE_NAME:
973
974
          break;
974
975
        case SPREADSHEET_EXCEL_READER_TYPE_FORMAT:
975
 
          $indexCode = v($data, $pos + 4);
 
976
          $indexCode = parent::v($data, $pos + 4);
976
977
          if ($version == SPREADSHEET_EXCEL_READER_BIFF8) {
977
 
            $numchars = v($data, $pos + 6);
 
978
            $numchars = parent::v($data, $pos + 6);
978
979
            if (ord($data[$pos + 8]) == 0) {
979
980
              $formatString = substr($data, $pos + 9, $numchars);
980
981
            } else {
987
988
          $this->formatRecords[$indexCode] = $formatString;
988
989
          break;
989
990
        case SPREADSHEET_EXCEL_READER_TYPE_FONT:
990
 
          $height = v($data, $pos + 4);
991
 
          $option = v($data, $pos + 6);
992
 
          $color = v($data, $pos + 8);
993
 
          $weight = v($data, $pos + 10);
 
991
          $height = parent::v($data, $pos + 4);
 
992
          $option = parent::v($data, $pos + 6);
 
993
          $color = parent::v($data, $pos + 8);
 
994
          $weight = parent::v($data, $pos + 10);
994
995
          $under = ord($data[$pos + 14]);
995
996
          $font = "";
996
997
          // Font name
1088
1089
                if (preg_match("/[^hmsday\/\-:\s\\\,AMP]/i", $tmp) == 0) { // found day and time format
1089
1090
                  $isdate = TRUE;
1090
1091
                  $formatstr = $tmp;
1091
 
                  $formatstr = str_replace(array('AM/PM', 'mmmm', 'mmm'), array('a', 'F', 'M'), $formatstr);
 
1092
                  $formatstr = str_replace(array('AM/PM', 'mmmm', 'mmm'), array('a', 'F', 'M'),
 
1093
                                           $formatstr);
1092
1094
                  // m/mm are used for both minutes and months - oh SNAP!
1093
1095
                  // This mess tries to fix for that.
1094
1096
                  // 'm' == minutes only if following h/hh or preceding s/ss
1101
1103
                  $formatstr = str_replace('mm', 'm', $formatstr);
1102
1104
                  // Convert single 'd' to 'j'
1103
1105
                  $formatstr = preg_replace("/(^|[^d])d([^d]|$)/", '$1j$2', $formatstr);
1104
 
                  $formatstr = str_replace(array('dddd', 'ddd', 'dd', 'yyyy', 'yy', 'hh', 'h'), array('l', 'D', 'd', 'Y', 'y', 'H', 'g'), $formatstr);
 
1106
                  $formatstr = str_replace(array('dddd', 'ddd', 'dd', 'yyyy', 'yy', 'hh', 'h'),
 
1107
                                           array('l', 'D', 'd', 'Y', 'y', 'H', 'g'), $formatstr);
1105
1108
                  $formatstr = preg_replace("/ss?/", 's', $formatstr);
1106
1109
                }
1107
1110
              }
1366
1369
        case SPREADSHEET_EXCEL_READER_TYPE_LABEL:
1367
1370
          $row = ord($data[$spos]) | ord($data[$spos + 1]) << 8;
1368
1371
          $column = ord($data[$spos + 2]) | ord($data[$spos + 3]) << 8;
1369
 
          $this->addcell($row, $column, substr($data, $spos + 8, ord($data[$spos + 6]) | ord($data[$spos + 7]) << 8));
 
1372
          $this->addcell($row, $column,
 
1373
                         substr($data, $spos + 8, ord($data[$spos + 6]) | ord($data[$spos + 7]) << 8));
1370
1374
          break;
1371
1375
        case SPREADSHEET_EXCEL_READER_TYPE_EOF:
1372
1376
          $cont = false;
1474
1478
      $totalseconds -= $secs;
1475
1479
      $hours = floor($totalseconds / (60 * 60));
1476
1480
      $mins = floor($totalseconds / 60) % 60;
1477
 
      $string = date($format, mktime($hours, $mins, $secs, $dateinfo["mon"], $dateinfo["mday"], $dateinfo["year"]));
 
1481
      $string = date($format,
 
1482
                     mktime($hours, $mins, $secs, $dateinfo["mon"], $dateinfo["mday"],
 
1483
                            $dateinfo["year"]));
1478
1484
    } else if ($type == 'number') {
1479
1485
      $rectype = 'number';
1480
1486
      $formatted = $this->_format_value($format, $numValue, $formatIndex);
1525
1531
 
1526
1532
  function addcell($row, $col, $string, $info=null)
1527
1533
  {
1528
 
    $this->sheets[$this->sn]['maxrow'] = max($this->sheets[$this->sn]['maxrow'], $row + $this->_rowoffset);
1529
 
    $this->sheets[$this->sn]['maxcol'] = max($this->sheets[$this->sn]['maxcol'], $col + $this->_coloffset);
 
1534
    $this->sheets[$this->sn]['maxrow'] = max($this->sheets[$this->sn]['maxrow'],
 
1535
                                             $row + $this->_rowoffset);
 
1536
    $this->sheets[$this->sn]['maxcol'] = max($this->sheets[$this->sn]['maxcol'],
 
1537
                                             $col + $this->_coloffset);
1530
1538
    $this->sheets[$this->sn]['cells'][$row + $this->_rowoffset][$col + $this->_coloffset] = $string;
1531
1539
    if ($this->store_extended_info && $info) {
1532
1540
      foreach ($info as $key => $val) {
1568
1576
      switch ($this->_encoderFunction) {
1569
1577
        case 'iconv' : $result = iconv('UTF-16LE', $this->_defaultEncoding, $string);
1570
1578
          break;
1571
 
        case 'mb_convert_encoding' : $result = mb_convert_encoding($string, $this->_defaultEncoding, 'UTF-16LE');
 
1579
        case 'mb_convert_encoding' : $result = mb_convert_encoding($string, $this->_defaultEncoding,
 
1580
                                                                   'UTF-16LE');
1572
1581
          break;
1573
1582
      }
1574
1583
    }
1583
1592
    }
1584
1593
    return $value;
1585
1594
  }
 
1595
 
1586
1596
}
 
 
b'\\ No newline at end of file'