Create spreadsheet by adding images and changing color of lines

Asked

Viewed 128 times

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 help in the change I need to make 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 linhs

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

Does anyone have any documentation or have ever done this?

  • I’m not familiar with php, but if you’re using Spreadsheet_excel_writer check out http://pear.php.net/manual/en/package.fileformats.spreadsheet-excel-writer.php, it might help.

2 answers

1

I ended up opting for the use of the library PHP Excel) .

It was the easiest way to effect this action.

-1

The simplest way to create an Excel spreadsheet is to modify the response header and turn the page into 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");
  • 1

    Reading the question carefully is the difference between passing the entrance exam or not (etc).

  • The solution solves the problem. It is certainly not the best way, so I did not understand this comment beast brasofilo

Browser other questions tagged

You are not signed in. Login or sign up in order to post.