Skip to content

Border in vertical merged cell #4397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
marcopiai opened this issue Mar 6, 2025 · 3 comments
Open

Border in vertical merged cell #4397

marcopiai opened this issue Mar 6, 2025 · 3 comments

Comments

@marcopiai
Copy link

I have this problem setting border in vertical merged cell (getOutline())
the border is visible only on the top, left and right of the first cell of the merged group

this is the code:
`<?php

require 'vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Color;

$spreadsheet = new Spreadsheet();
$activeWorksheet = $spreadsheet->getActiveSheet();

$activeWorksheet->setCellValue('B3', 'TEST');
$activeWorksheet->mergeCells("B3:B10");
$activeWorksheet->getStyle('B3')->getBorders()->getOutline()->setBorderStyle(Border::BORDER_THIN)->setColor(new Color('00000000'));

$writer = new Xlsx($spreadsheet);

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="bugtest.xlsx"');
$writer->save('php://output');

?>`

the result on excel is:

Image

any suggest?
could be a bug?

Thanks
Marco Piai

@oleibman
Copy link
Collaborator

oleibman commented Mar 6, 2025

You can get the result you want with getStyle(B3:B10) instead of getStyle(B3). I don't know offhand how styles for merged cells are supposed to work, so I am not sure whether the behavior that you describe is a bug. I will investigate.

@marcopiai
Copy link
Author

YES
this works. I hadn't thought about it

@oleibman
Copy link
Collaborator

oleibman commented Mar 7, 2025

My investigation of how Excel works is puzzling. Here's cell B2 with an outline border:

Image
And here's what happens when I merge B2:B4.

Image
The top border stays. The bottom border disappears, perhaps understandably. The left and right borders also disappear completely, which I don't understand at all. So Excel's behavior is no less unexpected than PhpSpreadsheet's. On this basis, I don't think there's a reason to change PhpSpreadsheet, but I'll leave this ticket open for a while to see if anyone thinks otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants