ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PhpOffice\PhpSpreadsheet\Shared\Xls Class Reference
+ Collaboration diagram for PhpOffice\PhpSpreadsheet\Shared\Xls:

Static Public Member Functions

static sizeCol ($sheet, $col='A')
 Get the width of a column in pixels. More...
 
static sizeRow ($sheet, $row=1)
 Convert the height of a cell from user's units to pixels. More...
 
static getDistanceX (Worksheet $sheet, $startColumn='A', $startOffsetX=0, $endColumn='A', $endOffsetX=0)
 Get the horizontal distance in pixels between two anchors The distanceX is found as sum of all the spanning columns widths minus correction for the two offsets. More...
 
static getDistanceY (Worksheet $sheet, $startRow=1, $startOffsetY=0, $endRow=1, $endOffsetY=0)
 Get the vertical distance in pixels between two anchors The distanceY is found as sum of all the spanning rows minus two offsets. More...
 
static oneAnchor2twoAnchor ($sheet, $coordinates, $offsetX, $offsetY, $width, $height)
 Convert 1-cell anchor coordinates to 2-cell anchor coordinates This function is ported from PEAR Spreadsheet_Writer_Excel with small modifications. More...
 

Detailed Description

Definition at line 8 of file Xls.php.

Member Function Documentation

◆ getDistanceX()

static PhpOffice\PhpSpreadsheet\Shared\Xls::getDistanceX ( Worksheet  $sheet,
  $startColumn = 'A',
  $startOffsetX = 0,
  $endColumn = 'A',
  $endOffsetX = 0 
)
static

Get the horizontal distance in pixels between two anchors The distanceX is found as sum of all the spanning columns widths minus correction for the two offsets.

Parameters
string$startColumn
int$startOffsetXOffset within start cell measured in 1/1024 of the cell width
string$endColumn
int$endOffsetXOffset within end cell measured in 1/1024 of the cell width
Returns
int Horizontal measured in pixels

Definition at line 108 of file Xls.php.

109 {
110 $distanceX = 0;
111
112 // add the widths of the spanning columns
113 $startColumnIndex = Coordinate::columnIndexFromString($startColumn);
114 $endColumnIndex = Coordinate::columnIndexFromString($endColumn);
115 for ($i = $startColumnIndex; $i <= $endColumnIndex; ++$i) {
116 $distanceX += self::sizeCol($sheet, Coordinate::stringFromColumnIndex($i));
117 }
118
119 // correct for offsetX in startcell
120 $distanceX -= (int) floor(self::sizeCol($sheet, $startColumn) * $startOffsetX / 1024);
121
122 // correct for offsetX in endcell
123 $distanceX -= (int) floor(self::sizeCol($sheet, $endColumn) * (1 - $endOffsetX / 1024));
124
125 return $distanceX;
126 }
static columnIndexFromString($pString)
Column index from string.
Definition: Coordinate.php:265
static stringFromColumnIndex($columnIndex)
String from column index.
Definition: Coordinate.php:313
static sizeCol($sheet, $col='A')
Get the width of a column in pixels.
Definition: Xls.php:20
$i
Definition: disco.tpl.php:19

References $i, PhpOffice\PhpSpreadsheet\Cell\Coordinate\columnIndexFromString(), PhpOffice\PhpSpreadsheet\Shared\Xls\sizeCol(), and PhpOffice\PhpSpreadsheet\Cell\Coordinate\stringFromColumnIndex().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Xls\load().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDistanceY()

static PhpOffice\PhpSpreadsheet\Shared\Xls::getDistanceY ( Worksheet  $sheet,
  $startRow = 1,
  $startOffsetY = 0,
  $endRow = 1,
  $endOffsetY = 0 
)
static

Get the vertical distance in pixels between two anchors The distanceY is found as sum of all the spanning rows minus two offsets.

Parameters
int$startRow(1-based)
int$startOffsetYOffset within start cell measured in 1/256 of the cell height
int$endRow(1-based)
int$endOffsetYOffset within end cell measured in 1/256 of the cell height
Returns
int Vertical distance measured in pixels

Definition at line 139 of file Xls.php.

140 {
141 $distanceY = 0;
142
143 // add the widths of the spanning rows
144 for ($row = $startRow; $row <= $endRow; ++$row) {
145 $distanceY += self::sizeRow($sheet, $row);
146 }
147
148 // correct for offsetX in startcell
149 $distanceY -= (int) floor(self::sizeRow($sheet, $startRow) * $startOffsetY / 256);
150
151 // correct for offsetX in endcell
152 $distanceY -= (int) floor(self::sizeRow($sheet, $endRow) * (1 - $endOffsetY / 256));
153
154 return $distanceY;
155 }
static sizeRow($sheet, $row=1)
Convert the height of a cell from user's units to pixels.
Definition: Xls.php:63
$row

References $row, and PhpOffice\PhpSpreadsheet\Shared\Xls\sizeRow().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Xls\load().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ oneAnchor2twoAnchor()

static PhpOffice\PhpSpreadsheet\Shared\Xls::oneAnchor2twoAnchor (   $sheet,
  $coordinates,
  $offsetX,
  $offsetY,
  $width,
  $height 
)
static

Convert 1-cell anchor coordinates to 2-cell anchor coordinates This function is ported from PEAR Spreadsheet_Writer_Excel with small modifications.

Calculate the vertices that define the position of the image as required by the OBJ record.

    +------------+------------+
    |     A      |      B     |

+--—+---------—+---------—+ | |(x1,y1) | | | 1 |(A1)._______|______ | | | | | | | | | | | +--—+-—| BITMAP |--—+ | | | | | | 2 | |______________. | | | | (B2)| | | | (x2,y2)| +-— +---------—+---------—+

Example of a bitmap that covers some of the area from cell A1 to cell B2.

Based on the width and height of the bitmap we need to calculate 8 vars: $col_start, $row_start, $col_end, $row_end, $x1, $y1, $x2, $y2. The width and height of the cells are also variable and have to be taken into account. The values of $col_start and $row_start are passed in from the calling function. The values of $col_end and $row_end are calculated by subtracting the width and height of the bitmap from the width and height of the underlying cells. The vertices are expressed as a percentage of the underlying cell width as follows (rhs values are in pixels):

  x1 = X / W *1024
  y1 = Y / H *256
  x2 = (X-1) / W *1024
  y2 = (Y-1) / H *256

  Where:  X is distance from the left side of the underlying cell
          Y is distance from the top of the underlying cell
          W is the width of the cell
          H is the height of the cell
Parameters
Worksheet$sheet
string$coordinatesE.g. 'A1'
int$offsetXHorizontal offset in pixels
int$offsetYVertical offset in pixels
int$widthWidth in pixels
int$heightHeight in pixels
Returns
null|array

Definition at line 210 of file Xls.php.

211 {
212 [$col_start, $row] = Coordinate::indexesFromString($coordinates);
213 $row_start = $row - 1;
214
215 $x1 = $offsetX;
216 $y1 = $offsetY;
217
218 // Initialise end cell to the same as the start cell
219 $col_end = $col_start; // Col containing lower right corner of object
220 $row_end = $row_start; // Row containing bottom right corner of object
221
222 // Zero the specified offset if greater than the cell dimensions
223 if ($x1 >= self::sizeCol($sheet, Coordinate::stringFromColumnIndex($col_start))) {
224 $x1 = 0;
225 }
226 if ($y1 >= self::sizeRow($sheet, $row_start + 1)) {
227 $y1 = 0;
228 }
229
230 $width = $width + $x1 - 1;
231 $height = $height + $y1 - 1;
232
233 // Subtract the underlying cell widths to find the end cell of the image
234 while ($width >= self::sizeCol($sheet, Coordinate::stringFromColumnIndex($col_end))) {
235 $width -= self::sizeCol($sheet, Coordinate::stringFromColumnIndex($col_end));
236 ++$col_end;
237 }
238
239 // Subtract the underlying cell heights to find the end cell of the image
240 while ($height >= self::sizeRow($sheet, $row_end + 1)) {
241 $height -= self::sizeRow($sheet, $row_end + 1);
242 ++$row_end;
243 }
244
245 // Bitmap isn't allowed to start or finish in a hidden cell, i.e. a cell
246 // with zero height or width.
247 if (self::sizeCol($sheet, Coordinate::stringFromColumnIndex($col_start)) == 0) {
248 return null;
249 }
250 if (self::sizeCol($sheet, Coordinate::stringFromColumnIndex($col_end)) == 0) {
251 return null;
252 }
253 if (self::sizeRow($sheet, $row_start + 1) == 0) {
254 return null;
255 }
256 if (self::sizeRow($sheet, $row_end + 1) == 0) {
257 return null;
258 }
259
260 // Convert the pixel values to the percentage value expected by Excel
261 $x1 = $x1 / self::sizeCol($sheet, Coordinate::stringFromColumnIndex($col_start)) * 1024;
262 $y1 = $y1 / self::sizeRow($sheet, $row_start + 1) * 256;
263 $x2 = ($width + 1) / self::sizeCol($sheet, Coordinate::stringFromColumnIndex($col_end)) * 1024; // Distance to right side of object
264 $y2 = ($height + 1) / self::sizeRow($sheet, $row_end + 1) * 256; // Distance to bottom of object
265
266 $startCoordinates = Coordinate::stringFromColumnIndex($col_start) . ($row_start + 1);
267 $endCoordinates = Coordinate::stringFromColumnIndex($col_end) . ($row_end + 1);
268
269 return [
270 'startCoordinates' => $startCoordinates,
271 'startOffsetX' => $x1,
272 'startOffsetY' => $y1,
273 'endCoordinates' => $endCoordinates,
274 'endOffsetX' => $x2,
275 'endOffsetY' => $y2,
276 ];
277 }
static indexesFromString(string $coordinates)
Get indexes from a string coordinates.
Definition: Coordinate.php:52

References $row, PhpOffice\PhpSpreadsheet\Cell\Coordinate\indexesFromString(), PhpOffice\PhpSpreadsheet\Shared\Xls\sizeCol(), PhpOffice\PhpSpreadsheet\Shared\Xls\sizeRow(), and PhpOffice\PhpSpreadsheet\Cell\Coordinate\stringFromColumnIndex().

Referenced by PhpOffice\PhpSpreadsheet\Writer\Xls\buildWorksheetEschers().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sizeCol()

static PhpOffice\PhpSpreadsheet\Shared\Xls::sizeCol (   $sheet,
  $col = 'A' 
)
static

Get the width of a column in pixels.

We use the relationship y = ceil(7x) where x is the width in intrinsic Excel units (measuring width in number of normal characters) This holds for Arial 10.

Parameters
Worksheet$sheetThe sheet
string$colThe column
Returns
int The width in pixels

Definition at line 20 of file Xls.php.

21 {
22 // default font of the workbook
23 $font = $sheet->getParent()->getDefaultStyle()->getFont();
24
25 $columnDimensions = $sheet->getColumnDimensions();
26
27 // first find the true column width in pixels (uncollapsed and unhidden)
28 if (isset($columnDimensions[$col]) && $columnDimensions[$col]->getWidth() != -1) {
29 // then we have column dimension with explicit width
30 $columnDimension = $columnDimensions[$col];
31 $width = $columnDimension->getWidth();
32 $pixelWidth = Drawing::cellDimensionToPixels($width, $font);
33 } elseif ($sheet->getDefaultColumnDimension()->getWidth() != -1) {
34 // then we have default column dimension with explicit width
35 $defaultColumnDimension = $sheet->getDefaultColumnDimension();
36 $width = $defaultColumnDimension->getWidth();
37 $pixelWidth = Drawing::cellDimensionToPixels($width, $font);
38 } else {
39 // we don't even have any default column dimension. Width depends on default font
40 $pixelWidth = Font::getDefaultColumnWidthByFont($font, true);
41 }
42
43 // now find the effective column width in pixels
44 if (isset($columnDimensions[$col]) && !$columnDimensions[$col]->getVisible()) {
45 $effectivePixelWidth = 0;
46 } else {
47 $effectivePixelWidth = $pixelWidth;
48 }
49
50 return $effectivePixelWidth;
51 }
static cellDimensionToPixels($pValue, \PhpOffice\PhpSpreadsheet\Style\Font $pDefaultFont)
Convert column width from (intrinsic) Excel units to pixels.
Definition: Drawing.php:73
static getDefaultColumnWidthByFont(\PhpOffice\PhpSpreadsheet\Style\Font $font, $pPixels=false)
Get the effective column width for columns without a column dimension or column with width -1 For exa...
Definition: Font.php:554

References PhpOffice\PhpSpreadsheet\Shared\Drawing\cellDimensionToPixels(), and PhpOffice\PhpSpreadsheet\Shared\Font\getDefaultColumnWidthByFont().

Referenced by PhpOffice\PhpSpreadsheet\Shared\Xls\getDistanceX(), PhpOffice\PhpSpreadsheet\Reader\Xls\load(), and PhpOffice\PhpSpreadsheet\Shared\Xls\oneAnchor2twoAnchor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sizeRow()

static PhpOffice\PhpSpreadsheet\Shared\Xls::sizeRow (   $sheet,
  $row = 1 
)
static

Convert the height of a cell from user's units to pixels.

By interpolation the relationship is: y = 4/3x. If the height hasn't been set by the user we use the default value. If the row is hidden we use a value of zero.

Parameters
Worksheet$sheetThe sheet
int$rowThe row index (1-based)
Returns
int The width in pixels

Definition at line 63 of file Xls.php.

64 {
65 // default font of the workbook
66 $font = $sheet->getParent()->getDefaultStyle()->getFont();
67
68 $rowDimensions = $sheet->getRowDimensions();
69
70 // first find the true row height in pixels (uncollapsed and unhidden)
71 if (isset($rowDimensions[$row]) && $rowDimensions[$row]->getRowHeight() != -1) {
72 // then we have a row dimension
73 $rowDimension = $rowDimensions[$row];
74 $rowHeight = $rowDimension->getRowHeight();
75 $pixelRowHeight = (int) ceil(4 * $rowHeight / 3); // here we assume Arial 10
76 } elseif ($sheet->getDefaultRowDimension()->getRowHeight() != -1) {
77 // then we have a default row dimension with explicit height
78 $defaultRowDimension = $sheet->getDefaultRowDimension();
79 $rowHeight = $defaultRowDimension->getRowHeight();
80 $pixelRowHeight = Drawing::pointsToPixels($rowHeight);
81 } else {
82 // we don't even have any default row dimension. Height depends on default font
83 $pointRowHeight = Font::getDefaultRowHeightByFont($font);
84 $pixelRowHeight = Font::fontSizeToPixels($pointRowHeight);
85 }
86
87 // now find the effective row height in pixels
88 if (isset($rowDimensions[$row]) && !$rowDimensions[$row]->getVisible()) {
89 $effectivePixelRowHeight = 0;
90 } else {
91 $effectivePixelRowHeight = $pixelRowHeight;
92 }
93
94 return $effectivePixelRowHeight;
95 }
static pointsToPixels($pValue)
Convert points to pixels.
Definition: Drawing.php:113
static getDefaultRowHeightByFont(\PhpOffice\PhpSpreadsheet\Style\Font $font)
Get the effective row height for rows without a row dimension or rows with height -1 For example,...
Definition: Font.php:586
static fontSizeToPixels($fontSizeInPoints)
Calculate an (approximate) pixel size, based on a font points size.
Definition: Font.php:362

References $row, PhpOffice\PhpSpreadsheet\Shared\Font\fontSizeToPixels(), PhpOffice\PhpSpreadsheet\Shared\Font\getDefaultRowHeightByFont(), and PhpOffice\PhpSpreadsheet\Shared\Drawing\pointsToPixels().

Referenced by PhpOffice\PhpSpreadsheet\Shared\Xls\getDistanceY(), PhpOffice\PhpSpreadsheet\Reader\Xls\load(), and PhpOffice\PhpSpreadsheet\Shared\Xls\oneAnchor2twoAnchor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: