Closed SSiwek closed 4 years ago
For ALL Export using yii2-export ... You need to use PHP Spreadsheet formatting rules and settings to achieve the table export format you need. Check docs for PHPSpreadsheet and configure that in yii2-export settings.
Hi
why did you close?
It does not work on your pages!
All other "All Export" do produce a table on your page! Only pdf does not work - On YOUR page.
so there has to be a bug.
regards Sven
Have reopened ... need to check what your issue is. Can you mention what you expect to happen which was working earlier and now not working?
Fixed via the above latest commit.
Hi Kartik, thank you for the fix.
I am stuck right now.
I try to get a title on the pdf. Without luck
'exportConfig' => [
ExportMenu::FORMAT_PDF => [
'options' => ['title' => 'Abrakadabra',],
'pdfConfig' => [
'options' => ['title' => 'Simsalabin',],
'methods' => [
'SetTitle' => 'Klimbim',
],
],
],
],
None of the above do work. It would be nice if you can help me on that.
Thank you in advance Sven
Set title
for the spreadsheet within ExportMenu::docProperties
- this will be used as the PDF title as well.
For example:
echo ExportMenu::widget([
'docProperties' => [
'title' => 'Your Custom Title'
],
// all other export menu settings
]);
Sorry.. me again ... and stuck
I try to set header and footer now. But it wont work
I permutated SetHeader in so many ways...
ExportMenu::widget([ 'docProperties' => [ 'title' => $this->title, ], 'selectedColumns'=> [ 2, 3, 4, 5, 6], // Col seq 2 to 6 'hiddenColumns'=>[0, 1, 7,8], 'dataProvider' => $dataProvider, 'columns' => $gridColumns, 'exportConfig' => [ ExportMenu::FORMAT_TEXT => false, ExportMenu::FORMAT_HTML => false, ExportMenu::FORMAT_EXCEL => false,
ExportMenu::FORMAT_PDF => [
'SetHeader' => 'My custom headeraa',
'SetFooter' => 'My custom footeraa',
'methods' => [
'SetHeader' => 'My custom headerbb',
'SetFooter' => 'My custom footerbb',
],
'pdfConfig' => [
'methods' => [
'SetHeader' => 'My custom headercc',
'SetFooter' => 'My custom footercc',
],
],
'setHeader' => 'My custom header11',
'setFooter' => 'My custom footer11',
'methods' => [
'setHeader' => 'My custom header22',
'setFooter' => 'My custom footer22',
],
'pdfConfig' => [
'methods' => [
'setHeader' => 'My custom header33',
'setFooter' => 'My custom footer33',
],
],
'SetHeader' => ['My custom headera'],
'SetFooter' => ['My custom footera'],
'methods' => [
'SetHeader' => ['My custom headerb'],
'SetFooter' => ['My custom footerb'],
],
'pdfConfig' => [
'methods' => [
'SetHeader' => ['My custom headerc'],
'SetFooter' => ['My custom footerc'],
],
],
'setHeader' => ['My custom header1'],
'setFooter' => ['My custom footer1'],
'methods' => [
'setHeader' => ['My custom header2'],
'setFooter' => ['My custom footer2'],
],
'pdfConfig' => [
'methods' => [
'setHeader' => ['My custom header3'],
'setFooter' => ['My custom footer3'],
],
],
],
],
'dropdownOptions' => [
'label' => 'Alles Exportieren',
'class' => 'btn btn-outline-secondary'
]
]);
Suggest you to read PHPSpreadsheet Library documentation to control formatting instead of the PDF settings. Note that because PHPSpreadsheet uses its own way to format output including PDF extensions, you may not be able to control most PDF settings except basic ones. Most of the yii2-export
output is controlled via PHPSpreadsheet Settings. Note that ExportMenu uses PHPSpreadsheet Library to render.
ExportMenu::docProperties
I mentioned earlier basically controlls PhpSpreadsheet document properties.
Header and footer of a PHPSpreadsheet example is described in their docs here.
Refer ExportMenu docs on how to set them.
Within ExportMenu, you can set onInitExcel
, onInitSheet
, or onRenderSheet
function callback to set the Sheet's properties.
Also, you can use other ExportMenu properties as function callbacks to format your spreadsheet output .... like onInitWriter
, onRenderHeaderCell
, onRenderFooterCell
, onRenderDataCell
etc.
Hi Kartik,
thank you for your help. I tried to get a header on the pages of that pdf. Without any luck.
You may update your Documentaion on onInitExcel because it provides a spreadsheet, not a (work)sheet.
Trying to access 'onInitWriter' $writer gives me : Cannot access protected property kartik\export\ExportWriterPdf::$spreadsheet
I really don't know what I am missing. It can't be that hard to get a header on the page.
ExportMenu::widget([ 'docProperties' => [ 'title' => $this->title, ],
'onRenderSheet' => function ($sheet,$widget){
$oo = $sheet->getHeaderFooter();
$oo->setOddHeader('&C&HPlease treat this document as confidential!');
$oo->setEvenHeader('&C&HPlease treat this document as confidential!');
},
'onInitSheet' => function ($sheet,$widget){
$oo = $sheet->getHeaderFooter();
$oo->setOddHeader('&C&HPlease treat this document as confidential!');
$oo->setEvenHeader('&C&HPlease treat this document as confidential!');
},
'onInitExcel' => function ($spreadsheet,$widget){
$oo = $spreadsheet->getActiveSheet()->getHeaderFooter();
$oo->setOddHeader('&C&HPlease treat this document as confidential!');
$oo->setEvenHeader('&C&HPlease treat this document as confidential!');
},
'onInitWriter' => function ($writer,$widget){
$writer->pdfConfig = [
'methods' => [
'SetHeader' =>
['odd' => 'Header', 'even' => 'Header']
],
];
},
'showConfirmAlert' => false,
'target' => ExportMenu::TARGET_BLANK,
'selectedColumns'=> [ 2, 3, 4, 5, 6], // Col seq 2 to 6
'hiddenColumns'=>[0, 1, 7,8],
'dataProvider' => $dataProvider,
'columns' => $gridColumns,
'exportConfig' => [
ExportMenu::FORMAT_TEXT => false,
ExportMenu::FORMAT_HTML => false,
ExportMenu::FORMAT_EXCEL => false,
],
'dropdownOptions' => [
'label' => 'Alles Exportieren',
'class' => 'btn btn-outline-secondary'
]
]);
Sven
Prerequisites
master
branch of yii2-export.Steps to reproduce the issue
See the difference in PDF
Expected behavior and actual behavior
When I follow those steps, I see...
On Page Export there are Gridlines ( a nice formatted table ) On All Export it is totally unformatted.
I was expecting to see a nice format on both cases.
Environment
It's on your demo pages.
Browsers
Operating System
Libraries
Isolating the problem
regards Sven