|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Xls\Record; |
|
4
|
|
|
|
|
5
|
|
|
use Xls\Biff8; |
|
6
|
|
|
|
|
7
|
|
|
class ContinueRecord extends AbstractRecord |
|
8
|
|
|
{ |
|
9
|
|
|
const NAME = 'CONTINUE'; |
|
10
|
|
|
const ID = 0x003C; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Excel limits the size of BIFF records. In Excel 97 the limit is 8228 bytes. |
|
14
|
|
|
* Records that are longer than these limits |
|
15
|
|
|
* must be split up into CONTINUE blocks. |
|
16
|
|
|
* |
|
17
|
|
|
* This function takes a long BIFF record and inserts CONTINUE records as |
|
18
|
|
|
* necessary. |
|
19
|
|
|
* |
|
20
|
|
|
* @param string $data The original binary data to be written |
|
21
|
|
|
* |
|
22
|
|
|
* @return string Сonvenient string of continue blocks |
|
23
|
|
|
*/ |
|
24
|
|
|
public function getData($data) |
|
25
|
|
|
{ |
|
26
|
|
|
//reserve 4 bytes for header |
|
27
|
|
|
$limit = Biff8::LIMIT - 4; |
|
28
|
|
|
|
|
29
|
|
|
// The first bytes below limit remain intact. However, we have to change |
|
30
|
|
|
// the length field of the record. |
|
31
|
|
|
$recordId = substr($data, 0, 2); |
|
32
|
|
|
$newRecordSize = $limit - 4; |
|
33
|
|
|
$recordData = substr($data, 4, $newRecordSize); |
|
34
|
|
|
$result = $recordId . pack("v", $newRecordSize) . $recordData; |
|
35
|
|
|
|
|
36
|
|
|
$data = substr($data, $newRecordSize + 4); |
|
37
|
|
|
$result .= $this->getDataRaw($data); |
|
38
|
|
|
|
|
39
|
|
|
return $result; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function getDataRaw($data) |
|
43
|
|
|
{ |
|
44
|
|
|
//reserve 4 bytes for header |
|
45
|
|
|
$limit = Biff8::LIMIT - 4; |
|
46
|
|
|
|
|
47
|
|
|
$dataLength = strlen($data); |
|
48
|
|
|
|
|
49
|
|
|
$result = ''; |
|
50
|
|
|
|
|
51
|
|
|
// Retrieve chunks of 8224 bytes +4 for the header |
|
52
|
|
|
for ($i = 0; $i < $dataLength - $limit; $i += $limit) { |
|
53
|
|
|
$chunk = substr($data, $i, $limit); |
|
54
|
|
|
$result .= $this->getFullRecord($chunk); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
// Retrieve the last chunk of data |
|
58
|
|
|
$lastChunkLength = $dataLength - $i; |
|
59
|
|
|
if ($lastChunkLength > 0) { |
|
60
|
|
|
$lastChunk = substr($data, $i, $lastChunkLength); |
|
61
|
|
|
$result .= $this->getFullRecord($lastChunk); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
return $result; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|