20 public static function sizeCol($sheet, $col =
'A')
23 $font = $sheet->getParent()->getDefaultStyle()->getFont();
25 $columnDimensions = $sheet->getColumnDimensions();
28 if (isset($columnDimensions[$col]) && $columnDimensions[$col]->getWidth() != -1) {
30 $columnDimension = $columnDimensions[$col];
31 $width = $columnDimension->getWidth();
33 } elseif ($sheet->getDefaultColumnDimension()->getWidth() != -1) {
35 $defaultColumnDimension = $sheet->getDefaultColumnDimension();
36 $width = $defaultColumnDimension->getWidth();
44 if (isset($columnDimensions[$col]) && !$columnDimensions[$col]->getVisible()) {
45 $effectivePixelWidth = 0;
47 $effectivePixelWidth = $pixelWidth;
50 return $effectivePixelWidth;
66 $font = $sheet->getParent()->getDefaultStyle()->getFont();
68 $rowDimensions = $sheet->getRowDimensions();
71 if (isset($rowDimensions[
$row]) && $rowDimensions[$row]->getRowHeight() != -1) {
73 $rowDimension = $rowDimensions[
$row];
74 $rowHeight = $rowDimension->getRowHeight();
75 $pixelRowHeight = (int) ceil(4 * $rowHeight / 3);
76 } elseif ($sheet->getDefaultRowDimension()->getRowHeight() != -1) {
78 $defaultRowDimension = $sheet->getDefaultRowDimension();
79 $rowHeight = $defaultRowDimension->getRowHeight();
88 if (isset($rowDimensions[$row]) && !$rowDimensions[$row]->getVisible()) {
89 $effectivePixelRowHeight = 0;
91 $effectivePixelRowHeight = $pixelRowHeight;
94 return $effectivePixelRowHeight;
108 public static function getDistanceX(
Worksheet $sheet, $startColumn =
'A', $startOffsetX = 0, $endColumn =
'A', $endOffsetX = 0)
115 for (
$i = $startColumnIndex;
$i <= $endColumnIndex; ++
$i) {
120 $distanceX -= (int) floor(self::sizeCol($sheet, $startColumn) * $startOffsetX / 1024);
123 $distanceX -= (int) floor(self::sizeCol($sheet, $endColumn) * (1 - $endOffsetX / 1024));
139 public static function getDistanceY(
Worksheet $sheet, $startRow = 1, $startOffsetY = 0, $endRow = 1, $endOffsetY = 0)
145 $distanceY += self::sizeRow($sheet,
$row);
149 $distanceY -= (int) floor(self::sizeRow($sheet, $startRow) * $startOffsetY / 256);
152 $distanceY -= (int) floor(self::sizeRow($sheet, $endRow) * (1 - $endOffsetY / 256));
213 $row_start =
$row - 1;
219 $col_end = $col_start;
220 $row_end = $row_start;
226 if ($y1 >= self::sizeRow($sheet, $row_start + 1)) {
230 $width = $width + $x1 - 1;
231 $height = $height + $y1 - 1;
240 while ($height >= self::sizeRow($sheet, $row_end + 1)) {
241 $height -= self::sizeRow($sheet, $row_end + 1);
253 if (self::sizeRow($sheet, $row_start + 1) == 0) {
256 if (self::sizeRow($sheet, $row_end + 1) == 0) {
262 $y1 = $y1 / self::sizeRow($sheet, $row_start + 1) * 256;
264 $y2 = ($height + 1) / self::sizeRow($sheet, $row_end + 1) * 256;
270 'startCoordinates' => $startCoordinates,
271 'startOffsetX' => $x1,
272 'startOffsetY' => $y1,
273 'endCoordinates' => $endCoordinates,
static sizeCol($sheet, $col='A')
Get the width of a column in pixels.
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...
static cellDimensionToPixels($pValue, \PhpOffice\PhpSpreadsheet\Style\Font $pDefaultFont)
Convert column width from (intrinsic) Excel units to pixels.
static pointsToPixels($pValue)
Convert points to pixels.
static oneAnchor2twoAnchor($sheet, $coordinates, $offsetX, $offsetY, $width, $height)
Convert 1-cell anchor coordinates to 2-cell anchor coordinates This function is ported from PEAR Spre...
static fontSizeToPixels($fontSizeInPoints)
Calculate an (approximate) pixel size, based on a font points size.
static indexesFromString(string $coordinates)
Get indexes from a string coordinates.
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 span...
static columnIndexFromString($pString)
Column index from string.
static stringFromColumnIndex($columnIndex)
String from column index.
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...
static sizeRow($sheet, $row=1)
Convert the height of a cell from user's units to pixels.
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 sp...