Excel PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • trpost@gmail.com

    #1

    Excel PHP

    I am using a set of functions that seem to be pretty common for using
    an associative array to write data to an .XLS file. This work fine for
    the most part, however I have problems writting a number to Excel on a
    Solaris system, whereas it works fine on a Windows system using the
    same PHP version (5.05). I have isolated the code to the following
    function:

    /**
    * Excel worksheet cell insertion
    * (single-worksheet supported only)
    * @access private
    * @param (int) $row worksheet row number
    (0...65536)
    * @param (int) $col worksheet column number
    (0..255)
    * @param (mixed) $val worksheet row number
    */
    function _xlsWriteCell($ row, $col, $val)
    {
    if (is_float($val) || is_int($val))
    {
    // doubles, floats, integers
    $str = pack(str_repeat ($this->bin[$this->endian], 5),
    0x203, 14, $row, $col, 0x0);
    $str .= pack("d", $val);
    }
    else
    {
    // everything else is treated as a string
    $l = strlen($val);
    $str = pack(str_repeat ($this->bin[$this->endian], 6),
    0x204, 8 + $l, $row, $col, 0x0, $l);
    $str .= $val;
    }
    fwrite($this->fp, $str);
    $this->position += strlen($str);
    return strlen($str);
    }

    Specifically it looks like the problem is happening here:

    if (is_float($val) || is_int($val))
    {
    // doubles, floats, integers
    $str = pack(str_repeat ($this->bin[$this->endian], 5),
    0x203, 14, $row, $col, 0x0);
    $str .= pack("d", $val);
    }

    My guess is that where it is doing pack("d", $val); that a DOUBLE is
    treated different on a windows versus solaris system. I tried changing
    this "d" to other things such as Long, Float, and others, but it just
    prints garbage when I do so...

    Any ideas on how to get this to write a number properly on Solaris, or
    how to interpret the 2 pack statements above to get an idea what
    exactly it is doing?

    Thanks

  • jodleren

    #2
    Re: Excel PHP

    On Apr 9, 5:55 pm, trp...@gmail.co m wrote:
    I am using a set of functions that seem to be pretty common for using
    an associative array to write data to an .XLS file. This work fine for
    the most part, however I have problems writting a number to Excel on a
    Solaris system, whereas it works fine on a Windows system using the
    same PHP version (5.05). I have isolated the code to the following
    function:
    Not quite sure of this, but maybe this can help you:

    $fExcel=fopen($ excelfile, "w");
    fwrite($fExcel, "<html><head><S TYLE TYPE=\"text/css\">");
    fwrite($fExcel, " <!-- .number2dec {mso-number-format: Fixed;} \r
    \n");
    fwrite($fExcel, " .number0dec {mso-number-format: 0\\;} -->\r\n");
    fwrite($fExcel, "</STYLE></head><table border=1>\r\n") ;

    fwrite($fExcel, "<tr><td class=number2de c>1.2



    Comment

    Working...