Create worksheet by adding images and changing line color

3

This method creates an Excel spreadsheet, with int and string :

public function arrayToXls($input) {
    // BoF
    $ret = pack('ssssss', 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);

    // array_values is used to ensure that the array is numerically indexed
    foreach (array_values($input) as $lineNumber => $row) {
        foreach (array_values($row) as $colNumber => $data) {
            if (is_numeric($data)) {
                // number, store as such
                $ret .= pack('sssssd', 0x203, 14, $lineNumber, $colNumber, 0x0, $data);
            } else {
                // everything else store as string
                $len = strlen($data);
                $ret .= pack('ssssss', 0x204, 8 + $len, $lineNumber, $colNumber, 0x0, $len) . $data;

            }
        }
    }


    //EoF
    $ret .= pack('ss', 0x0A, 0x00);

    return $ret;
}

I would like to add an image, could you help with the change I need to make in this line for this?

$ret .= pack('ssssss', 0x204, 8 + $len, $lineNumber, $colNumber, 0x0, $len) . $data;

And I also need to change the color of the line

$ret .= pack('ss', 0x0A, 0x00);

Does anyone have any documentation or have you already done this?

    
asked by anonymous 17.03.2015 / 14:00

2 answers

1

I ended up opting to use the PHP Excel library.)

It was the easiest way to do this.

    
22.07.2015 / 22:25
-1

The simplest way to create an Excel spreadsheet is to modify the response header and turn the page into a spreadsheet:

$fileName = "planilha.xls";
header("Content-type: application/vnd.ms-excel");
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=$fileName");
header("Pragma: no-cache");
    
19.03.2015 / 23:04