μνΈμ νμ΄νΌλ§ν¬λ₯Ό μ½μ νλ €κ³ νμΌλ ν μ€νΈ νμμΌ λΏμ λλ€. ν΄λ¦ κ°λ₯ν νμ΄νΌλ§ν¬λ₯Ό μ½μ νλ €λ©΄ μ΄λ»κ² ν΄μΌ ν©λκΉ?
μ΄λ»κ² μλνλμ§ λ³΄μ¬μ£Όμκ³ μλμΌλ‘ μ 곡λλ github μ΄μ ν νλ¦Ώμ μλ €μ£ΌμΈμ.
`$candidate; //Collection object from model
foreach ($candidates as $key => $model) {
if($model->grade == 'Z') {
$model->grade="Reject";
}
$model->access_token=url('static-access/'.$model->access_token);`
access_tokenμ μμ ν URLλ‘ κ΅μ²΄νκ³ μμ΅λλ€. κ·Έλ° λ€μ 컬λ μ κ°μ²΄λ₯Ό μλμ κ°μ΄ λ°°μ΄λ‘ λ³νν©λλ€.
`foreach ($candidates as $candidate) {
$candidatesArray[] = $candidate->toArray();
}`
κ·Έλ° λ€μ μλμ κ°μ΄ λ°°μ΄μμ μνΈλ₯Ό μμ±ν©λλ€.
`$sheet=$excel->sheet('sheet1', function($sheet) use ($candidatesArray,$jd) {
$sheet->fromArray($candidatesArray, null, 'A1', false, false);
});`
μ΄ μ€ν¬λ¦½νΈμμ μ€μ λ‘ νμμ λ°λΌ λ°μ΄ν°λ₯Ό λ΄λ³΄λ΄μ§λ§ νμ΄νΌλ§ν¬λ ν΄λ¦ κ°λ₯ν λ§ν¬κ° μλ ν μ€νΈ νμμΌλ‘ λ΄λ³΄λ λλ€. @patrickbrowers
PHPExcel κΈ°λ³Έ λ©μλλ₯Ό μ¬μ©νμ¬ λ€μκ³Ό κ°μ΄ ν΄μΌ νλ€κ³ μκ°ν©λλ€.
$sheet->getCell('E26')
->getHyperlink()
->setUrl('http://examle.com/uploads/cv/' . $cellValue)
->setTooltip('Click here to access file');
https://github.com/PHPOffice/PHPExcel/blob/develop/Documentation/markdown/Overview/08-Recipes.md#change -a-cell-into-a-clickable-url
@patrickbrouwers κ°μ¬ν©λλ€. νμ§λ§ setTooltipμ΄ μλνμ§ μμ΅λλ€(λΉ μ
).
μ μ΄λ "maatwebsite/excel": "~2.1.0"
λ²μ μ κ²½μ°.
setValueλ₯Ό μ¬μ©νμ¬ λ¬΄μΈκ°λ₯Ό ν μ€νΈλ‘ νμνκ³ μμ΅λλ€.
λν λ΄ ν μ€νΈλ IDμ΄λ©° μ«μ νλ(E νκΈ°λ² μ¬μ©)λ‘ ν΄μλμμ΅λλ€. μ΄ λ¬Έμ λ₯Ό ν΄κ²°νκΈ° μν΄ λ€μμ μ¬μ©νκ³ μμ΅λλ€.
->setValueExplicit($fbId, PHPExcel_Cell_DataType::TYPE_STRING)
setTooltip
λ μ
μλ‘ λ§μ°μ€λ₯Ό κ°μ Έκ°λ©΄ νμλλ ν
μ€νΈμ
λλ€. μ€μ λ‘ μ¬μ©νκΈ° μ μ setValue
λλ setValueExplicit
λ₯Ό μνν΄μΌ ν©λλ€.
Excel νμΌμμ λ§ν¬κ° μμ±λμ§ μλ μ΄μ λ₯Ό νμ
νλ λ° λ무 μ€λ μκ°μ 보λμ΅λλ€. $sheet->cell("A1")
μ $sheet->getCell("A1")
λ κ°μ§ μμ΅λλ€. λ€μκ³Ό κ°μ μΌμ νλ κ²½μ°κ° λ§μμ΅λλ€.
$sheet->cell($cellLetter.$rowIndex, $url)
->getHyperlink()
->setUrl($url);
μλνμ§ μμμ§λ§ Method [...] doesn't exist for ...
μ κ°μ μ€λ₯λ μμ±νμ§ μμμ΅λλ€. λ΄ μ½λλ₯Ό λ€μκ³Ό κ°μ΄ λ³κ²½:
$sheet->getCell($cellLetter.$rowIndex) // A1, B2
->setValueExplicit("Click Here", \PHPExcel_Cell_DataType::TYPE_STRING);
$sheet->getStyle($cellLetter.$rowIndex)
->applyFromArray($urlStyle); // Blue, Bold
$sheet->getCell($cellLetter.$rowIndex)
->getHyperlink()
->setUrl($url);
λ΄ λ¬Έμ λ₯Ό ν΄κ²°νμ΅λλ€. κ°μ λ¬Έμ λ‘ λ―Έλμ λκ΅°κ°λ₯Ό λμΈ μ μμ΅λλ€.
λ΄ λ¬Έμ λ₯Ό ν΄κ²°νμμμ€. μ΄κ²μ λ΄ μ½λμ λλ€.
$sheet->getCell($cell)
->getHyperlink()
->setUrl($url);
$sheet->getStyle($cell)
->applyFromArray(array(
'font' => array(
'color' => ['rgb' => '0000FF'],
'underline' => 'single'
)
));
κ³ λ§μ ν @TimothyDLewis
@TimothyDLewis λλ @herarya μνΈλ₯Ό λ°λ³΅νλ λ°©λ²μ λν΄ λ¬Έμ λ₯Ό μΌμΌν¬ μ μμ΅λκΉ? - μ¬μ©ν μ 체 λ°©λ²μ λν΄ μ½λλ₯Ό μ‘°κΈ λ κ²μνμκ² μ΅λκΉ? (μ: $cellLetter.$rowIndex
λλ $cell
? )
λ°μ΄ν°λ² μ΄μ€μμ 5κ°μ μ΄μ΄ μλ κ°λ¨ν λ°°μ΄μ λ΄λ³΄λ΄κ³ μμ΅λλ€. μ΄κ²μ νλμ μνΈμ΄κ³ λ¨Έλ¦¬κΈ νμ΄ μμ΅λλ€. μΌλ¨ κ·Έκ²μ μ‘μΌλ©΄ λ¬Όλ‘ μλνλ λ€μ μ½λκ° μμ΅λλ€.
//$trademark = [an array of data with 5 columns and a header row];
Excel::create('trademarks', function($excel) use($trademarks) {
$excel->sheet('trademarks', function($sheet) use($trademarks) {
$sheet->fromArray($trademarks,null,'A1',false,false);
//need to iterate over $sheet, get each row, and find column 1 in that row and set a URL
})->export('xlsx');
$sheetλ₯Ό λ°λ³΅νκ³ URLμ μ¬μ©νμ¬ κ° ν(첫 λ²μ§Έ ν μ μΈ)μμ νλμ μ μ λ³κ²½νκ³ μΆμ΅λλ€. λλ μ΅λ 3κ°μ κΉμ foreach 루νλ₯Ό μλνμ΅λλ€(κ²°κ³Όκ° κ°μ²΄, λ°°μ΄μ΄λΌλ μ€λ₯κ° κ³μ λ°μνκ±°λ "PHPExcel_Exception Invalid cell μ’ν CREATOR in Cell.php(line 590)"μ΄ νμλ©λλ€. $sheet- >each (κ°κ° λ°©λ²μ΄ μλ€λ μ€λ₯μ΄λ―λ‘ νμΌμμ λ‘λν λλ§ μ¬μ©ν μ μλ λ°©λ²μμ΄ λΆλͺ ν¨).
setUrl("μνΈ://'ν
μ€νΈ'!A1")
κ·Έλ¬λ νμΌ λ§ν¬λ sheet://test!A1μ
λλ€.
μ?
v3.*λ₯Ό μ¬μ©ν λ νμ΄νΌλ§ν¬λ₯Ό μ€μ ν μ μμ΅λλ€.
<?php
namespace App\Exports;
use Excel;
use Maatwebsite\Excel\Sheet;
use Maatwebsite\Excel\Events\AfterSheet;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithHeadings;
use PhpOffice\PhpSpreadsheet\Cell\Hyperlink;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
class CommentsExport implements FromCollection, WithHeadings, WithMapping, ShouldAutoSize
{
// ...
public function custom()
{
Excel::extend(static::class, function (CommentsExport $export, Sheet $sheet) {
/** <strong i="6">@var</strong> Worksheet $sheet */
foreach ($sheet->getColumnIterator('H') as $row) {
foreach ($row->getCellIterator() as $cell) {
if (str_contains($cell->getValue(), '://')) {
$cell->setHyperlink(new Hyperlink($cell->getValue(), 'ηΉε»ζ₯ηεΎη'));
}
}
}
}, AfterSheet::class);
}
// ...
}
(new CommentsExport)->custom());
Excel::download(CommentsExport::class);
v3.*λ₯Ό μ¬μ©ν λ νμ΄νΌλ§ν¬λ₯Ό μ€μ ν μ μμ΅λλ€.
<?php namespace App\Exports; use Excel; use Maatwebsite\Excel\Sheet; use Maatwebsite\Excel\Events\AfterSheet; use Maatwebsite\Excel\Concerns\WithMapping; use Maatwebsite\Excel\Concerns\WithHeadings; use PhpOffice\PhpSpreadsheet\Cell\Hyperlink; use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\ShouldAutoSize; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; class CommentsExport implements FromCollection, WithHeadings, WithMapping, ShouldAutoSize { // ... public function custom() { Excel::extend(static::class, function (CommentsExport $export, Sheet $sheet) { /** <strong i="7">@var</strong> Worksheet $sheet */ foreach ($sheet->getColumnIterator('H') as $row) { foreach ($row->getCellIterator() as $cell) { if (str_contains($cell->getValue(), '://')) { $cell->setHyperlink(new Hyperlink($cell->getValue(), 'ηΉε»ζ₯ηεΎη')); } } } }, AfterSheet::class); } // ... }
(new CommentsExport)->custom()); Excel::download(CommentsExport::class);
μ μ©ν μ루μ μ΄μ§λ§ 리ν©ν λ§μ ν΅ν΄ λ μ΄ν΄νκΈ° μ½κ² ν μ μμ΅λλ€.
<?php
namespace App\Exports;
use Excel;
use Maatwebsite\Excel\Sheet;
// add event support
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\AfterSheet;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithHeadings;
use PhpOffice\PhpSpreadsheet\Cell\Hyperlink;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
class CommentsExport implements FromCollection, WithHeadings, WithMapping, ShouldAutoSize, WithEvents
{
// ...
/**
* <strong i="13">@return</strong> array
*/
public function registerEvents(): array
{
return [
AfterSheet::class => function(AfterSheet $event) {
/** <strong i="14">@var</strong> Worksheet $sheet */
foreach ($event->sheet->getColumnIterator('H') as $row) {
foreach ($row->getCellIterator() as $cell) {
if (str_contains($cell->getValue(), '://')) {
$cell->setHyperlink(new Hyperlink($cell->getValue(), 'Read'));
// Upd: Link styling added
$event->sheet->getStyle($cell->getCoordinate())->applyFromArray([
'font' => [
'color' => ['rgb' => '0000FF'],
'underline' => 'single'
]
]);
}
}
}
},
];
}
// ...
}
μ¬μ©λ²:
Excel::download(CommentsExport::class);
λΉμ μ΄ λ§μ΅λλ€. μ΄κ²μ λλ³΄λ€ λ λμ μ루μ μ λλ€. @AlexMcDee
@TimothyDLewis λλ @herarya μνΈλ₯Ό λ°λ³΅νλ λ°©λ²μ λν΄ λ¬Έμ λ₯Ό μΌμΌν¬ μ μμ΅λκΉ? - μ¬μ©ν μ 체 λ°©λ²μ λν΄ μ½λλ₯Ό μ‘°κΈ λ κ²μνμκ² μ΅λκΉ? (μ:
$cellLetter.$rowIndex
λλ$cell
? )λ°μ΄ν°λ² μ΄μ€μμ 5κ°μ μ΄μ΄ μλ κ°λ¨ν λ°°μ΄μ λ΄λ³΄λ΄κ³ μμ΅λλ€. μ΄κ²μ νλμ μνΈμ΄κ³ λ¨Έλ¦¬κΈ νμ΄ μμ΅λλ€. μΌλ¨ κ·Έκ²μ μ‘μΌλ©΄ λ¬Όλ‘ μλνλ λ€μ μ½λκ° μμ΅λλ€.
//$trademark = [an array of data with 5 columns and a header row]; Excel::create('trademarks', function($excel) use($trademarks) { $excel->sheet('trademarks', function($sheet) use($trademarks) { $sheet->fromArray($trademarks,null,'A1',false,false); //need to iterate over $sheet, get each row, and find column 1 in that row and set a URL })->export('xlsx');
$sheetλ₯Ό λ°λ³΅νκ³ URLμ μ¬μ©νμ¬ κ° ν(첫 λ²μ§Έ ν μ μΈ)μμ νλμ μ μ λ³κ²½νκ³ μΆμ΅λλ€. λλ μ΅λ 3κ°μ κΉμ foreach 루νλ₯Ό μλνμ΅λλ€(κ²°κ³Όκ° κ°μ²΄, λ°°μ΄μ΄λΌλ μ€λ₯κ° κ³μ λ°μνκ±°λ "PHPExcel_Exception Invalid cell μ’ν CREATOR in Cell.php(line 590)"μ΄ νμλ©λλ€. $sheet- >each (κ°κ° λ°©λ²μ΄ μλ€λ μ€λ₯μ΄λ―λ‘ νμΌμμ λ‘λν λλ§ μ¬μ©ν μ μλ λ°©λ²μμ΄ λΆλͺ ν¨).
λ°κ²¬ ν μ€λμ μ»μμ΅λλ€ ....
https://stackoverflow.com/questions/41053636/laravel-excel-export-each-cell-style
μ΄λ»κ² μ€λ₯ λ©μμ§ μμ§ λͺ¨λμ λ°νν©λκΉ?
Googleμμ μ¬κΈ°μ μ€λ μ¬λμ μν κ°λ¨ν λ©λͺ¨μ λλ€. μ 곡λ μ루μ μ λν΄ @mouyong @AlexMcDee μκ² κ°μ¬λ립λλ€.
$sheet->getColumnIterator('H')
λ₯Ό μ¬μ©νλ λμ λ μ΄ $sheet->getColumnIterator('H', 'H')
μΈ λ λ²μ§Έ 맀κ°λ³μλ₯Ό μ§μ νλ κ²μ΄ μ€μν©λλ€.
λ μ΄μ΄ μμΌλ©΄ λ°λ³΅μλ λ§μ§λ§ μ΄κΉμ§ κ° μ΄μ λ°λ³΅ν©λλ€ .
νμμ²λΌ λ§μ§λ§ μ΄μ΄ μλ μνΈ μ€κ°μ μ΄μ λν νμ΄νΌλ§ν¬λ₯Ό λ§λ€κ³ μ ν λ μ΄κ²μ μμμ°¨λ Έμ΅λλ€.
λ΄κ° λ°λΌνκ² λ λ λ€λ₯Έ μ κ·Ό λ°©μμ Excelμ νμ΄νΌλ§ν¬ κΈ°λ₯μ μ¬μ©νλ κ²μ
λλ€.
μλ₯Ό λ€μ΄ λμΌν ν
μ€νΈκ° μλ sheet2μμ sheet1(λ²μ A1:A20)μ μ
λ‘ μ°κ²°λλ νμ΄νΌλ§ν¬λ₯Ό λ§λ€κ³ μΆμμ΅λλ€.
λ΄ μνΈμμ 2
public function array(): array
{
$data = [
['Id'],
];
foreach ($this->data as $id) {
$idformula = '=HYPERLINK("#"&CELL("address", INDEX(Sheet1!A1:A20, MATCH("'.$id.'",Sheet1!A1:A20,0), 1)),"'.$id.'")';
array_push($data, [$idformula]);
}
return $data;
}
μ€νμΌμ μ§μ νλ €λ©΄:
public function styles(Worksheet $sheet)
{
return [
'A' => ['font' => [
'color' => ['rgb' => '0000FF'],
'underline' => 'single',
]],
];
}
κ°μ₯ μ μ©ν λκΈ
μ μ©ν μ루μ μ΄μ§λ§ 리ν©ν λ§μ ν΅ν΄ λ μ΄ν΄νκΈ° μ½κ² ν μ μμ΅λλ€.
μ¬μ©λ²: