public function testMergedCells() { $book = new Book(file_get_contents(__DIR__ . '/xls/merged.xls')); $sheet = $book->getSheetByName('Sheet1'); $this->assertEquals([[0, 1, 1, 4], [1, 2, 0, 2], [0, 2, 4, 5]], $sheet->merged_cells); $this->assertEquals(XL_CELL_BLANK, $sheet[0][0]->ctype); $this->assertEquals(XL_CELL_BLANK, $sheet[0][2]->ctype); $this->assertEquals(XL_CELL_BLANK, $sheet[1][2]->ctype); $this->assertEquals(XL_CELL_BLANK, $sheet[1][4]->ctype); $this->assertEquals(XL_CELL_TEXT, $sheet[0][1]->ctype); $this->assertEquals(XL_CELL_TEXT, $sheet[1][0]->ctype); $this->assertEquals(XL_CELL_TEXT, $sheet[1][3]->ctype); $this->assertEquals(XL_CELL_NUMBER, $sheet[0][4]->ctype); $this->assertEquals('MERGED A1:D1', $sheet[0][1]->value); $this->assertEquals('MERGED A2:B2', $sheet[1][0]->value); $this->assertEquals('D2', $sheet[1][3]->value); $this->assertEquals(1.0, $sheet[0][4]->value, '', 0.001); }
/** * @param $data * @param $txos MSTxo[] */ public function handle_note($data, $txos) { $o = new Note(); $data_len = strlen($data); if ($this->biff_version < 80) { # <HHH list($o->rowx, $o->colx, $expected_bytes) = array_values(unpack("v3", substr($data, 0, 6))); $nb = strlen($data) - 6; assert($nb <= $expected_bytes); $pieces = [substr($data, 6)]; $expected_bytes -= $nb; while ($expected_bytes > 0) { list($rc2, $data2_len, $data2) = $this->book->readRecordParts(); assert($rc2 == XL_NOTE); list($dummy_rowx, $nb) = array_values(unpack('v2/x/va', substr($data2, 0, 6))); assert($dummy_rowx == 0xffff); assert($nb == $data2_len - 6); $pieces[] = substr($data2, 6); $expected_bytes -= $nb; } assert($expected_bytes == 0); $enc = $this->book->encoding ?: $this->book->deriveEncoding(); $o->text = join('', $pieces); $o->rich_text_runlist = [[0, 0]]; $o->show = 0; $o->row_hidden = 0; $o->col_hidden = 0; $o->author = ''; $o->_object_id = Null; $this->cell_note_map[$o->rowx][$o->colx] = $o; return; } # Excel 8.0+ # <HHHH list($o->rowx, $o->colx, $option_flags, $o->_object_id) = array_values(unpack("v4", substr($data, 0, 8))); $o->show = $option_flags >> 1 & 1; $o->row_hidden = $option_flags >> 7 & 1; $o->col_hidden = $option_flags >> 8 & 1; # XL97 dev kit book says NULL [sic] bytes padding between string count and string data # to ensure that string is word-aligned. Appears to be nonsense. list($o->author, $endpos) = Helper::unpack_unicode_update_pos($data, 8, 2); # There is a random/undefined byte after the author string (not counted in the # string length). # Issue 4 on github: Google Spreadsheet doesn't write the undefined byte. assert(in_array($data_len - $endpos, [0, 1])); if (isset($txos[$o->_object_id])) { $txo = $txos[$o->_object_id]; $o->text = $txo->text; $o->rich_text_runlist = $txo->rich_text_runlist; $this->cell_note_map[$o->rowx][$o->colx] = $o; } }
public function testCellValue() { $this->assertEquals('PROFIL', $this->sheet->cell_value(0, 0)); $this->assertEquals(100, $this->sheet->cell_value(1, 1)); $this->assertEquals(113, $this->sheet->cell_value(2, 2)); $this->assertEquals("2014-12-01 00:00:00", $this->sheet->cell_value(17, 2)); $this->assertEquals('12:03:00', $this->sheet->cell_value(18, 2)); $this->assertEquals('2015-12-01 13:37:01', $this->sheet->cell_value(19, 2)); $this->assertEquals('1900-01-01 00:00:00', $this->sheet->cell_value(20, 2)); $sheet = $this->book->getSheetByName('PROFILELEVELS'); $this->assertEquals(0.025, $sheet->cell_value(1, 1), null, 0.001); $this->assertEquals(265.212, $sheet->cell_value(1, 2), null, 0.001); $this->assertEquals('PROFIL', $this->sheet[0][0]->value); $this->assertEquals(100, $this->sheet[1][1]->value); $this->assertEquals(113, $this->sheet[2][2]->value); $this->assertEquals("2014-12-01 00:00:00", $this->sheet[17][2]->value); $this->assertEquals('12:03:00', $this->sheet[18][2]->value); $this->assertEquals('2015-12-01 13:37:01', $this->sheet[19][2]->value); $this->assertEquals('1900-01-01 00:00:00', $this->sheet[20][2]->value); $sheet = $this->book->getSheetByName('PROFILELEVELS'); $this->assertEquals(0.025, $sheet[1][1]->value, null, 0.001); $this->assertEquals(265.212, $sheet[1][2]->value, null, 0.001); }
function testCommentsFormatting() { $sheet = $this->book->getSheetByName('Formate'); $note = $sheet->cell_note_map[1][0]; $this->assertEquals([[0, 11], [11, 31], [12, 32], [13, 10]], $note->rich_text_runlist); }
public function setUp() { $this->book = new Book(file_get_contents(__DIR__ . '/xls/Formate.xls')); $this->sheet = $this->book->getSheetByName('Blätt1'); }