PHP Draw line between two cells on excel sheet

54 Views Asked by At

I need to draw line between two cells in excel sheet using php

In my laravel app I need to create an excel sheet and draw line between two cells for example b4 and f9 like this image

enter image description here

I tried to use phpspreadsheet package with this code

    // Create a new Spreadsheet
    $spreadsheet = new Spreadsheet();
    $worksheet = $spreadsheet->getActiveSheet();

    // Set values in cells
    $worksheet->setCellValue('A1', 'Cell 1');
    $worksheet->setCellValue('D4', 'Cell 2');

    // Add a drawing (line) between two cells
    $drawing = new Drawing();
    $drawing->setWorksheet($worksheet);
    $drawing->setName('Line');
    $drawing->setDescription('Line between cells');
    $drawing->setPath('../public/black_dot.png'); // 1x1 pixel image
    $drawing->setCoordinates('b4');
    $drawing->setResizeProportional(false);
    // $drawing->setWidth(100); // Adjust the width of the line
    $drawing->setHeight(2); // Adjust the height of the line

    // Save the spreadsheet
    $writer = new Xlsx($spreadsheet);
    $writer->save('map.xlsx');

it draw horizonal line starting from b4 I need a way to specify the second cell f9

I tried $drawing->setCoordinates2('f9'); but it draw a rectangle start from b4 to f9 cell.

I can specify offsets and rotations but I need to draw the line only by the info of cell numbers.

any help ? if anyone know another package to do the same task please advise

0

There are 0 best solutions below