Skip to content

Laravel Excel Export with Vlookup formula multiple sheets #3215

Answered by MarkBaker
tomekhun asked this question in Q&A
Discussion options

You must be logged in to vote

I don't know what the Laravel wrapper might be doing, but this works as expected in PhpSpreadsheet:

$spreadSheet = new Spreadsheet();
$workSheet = $spreadSheet->getActiveSheet();
$dataSheet = new \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet($spreadSheet, 'Data');
$spreadSheet->addSheet($dataSheet);

$data = [['XYZ', 'ABC'], ['WXY', 'DEF'], ['VWX', 'GHI'], ['UVW', 'JKL']];

$formula = '=VLOOKUP(A1,Data!B:C,2,false)';

$workSheet->getCell('A1')->setValue('VWX');
$workSheet->getCell('A2')->setValue($formula);
$dataSheet->fromArray($data, null, 'B1');

$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadSheet);
$writer->save("{$fileName}.xlsx");

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
6 replies
@MarkBaker
Comment options

@tomekhun
Comment options

@MarkBaker
Comment options

@tomekhun
Comment options

@tomekhun
Comment options

Comment options

You must be logged in to vote
1 reply
@tomekhun
Comment options

Answer selected by tomekhun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants