Home › Forums › Guriddo Suito PHP › Excel export
Tagged: excel, export, number format
Hi,
How can I define cell type for columns in excel export? Now every column is in excel’s ‘General’ format.
Hello,
The type of column is detected automatically from the script (based on the database table properties). There was some small problems with numeric type in true excel export.
Which Guriddo PHP version is used and which type of excel export is used?
It is possible to send us a script and a demo table definition demonstrating the problem?
Thank you.
Kind Regards
Will
Guriddo Support Team
Hi,
We’re using version 5.0.0 and I’ve tried with Excel5, Excel2007 and XML. XML works fine with numbers but it throws following error: “The file format differs from the format that the file name extension specifies” so it’s no good for us. Only real solution would be export in genuine excel -format. I’m not sure if demo helps because it’s pretty simple export with few text / number fields.
And one more question. I created a colModel for jqGrid. It contains following fields:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
array( 'name' => XXXX::FIELD_ACCOUNT_, 'classes' => '', 'editable' => false, 'align' => 'left', 'hidden' => false, 'hidedlg' => false, 'label' => '', 'sorttype' => 'number', 'formatter' => 'numeric', 'width' => 250, ), |
So does the ‘formatter’ -field have any influence on export cell types?
Hello,
Can you please try our demo download with 5.1.1 and see if the problem is fixed for you?
Unfortunately the formatter does not apply to excel (it is a client side solution) export. The formating depend on current (locale) excel settings for numbers and integers.
Kind Regards,
Will
Guriddo Support Team
Hi,
I tried it and it didn’t work as expected. Every cell is still in general -format.
Sample data:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
array( array ( 'AccountName' => 'Example Account #1', 'ProjectName' => 'Amigurumivirkkaus', 'SubprojectName' => 'Virkkausprosessi', 'SubprojectEndDate' => '29.10.2014', 'EstimatedCost' => '100.00', 'ResourcedInvoicing' => '200.00', ), array ( 'AccountName' => 'Example Account #2', 'ProjectName' => '1036', 'SubprojectName' => 'awsdf', 'SubprojectEndDate' => '14.08.2015', 'EstimatedCost' => '200.00', 'ResourcedInvoicing' => '300.00', ), ); |
Excel options:
1 2 3 4 5 6 7 8 9 10 11 |
array( "file_type" => "Excel5", "start_cell" => "A1", "font" => "Calibri", "font_size" => 11, "protect" => false, "creator" => "xxx", "author" => "xxx", ); |
Extracted from our controller:
1 2 3 4 5 6 7 8 9 10 11 |
$conn = new \jqGridArray(); $grid = new \jqGridRender($conn); // Data is it in $GLOBALS[Export::EXPORT_KEY] $grid->ExportCommand = "SELECT * FROM " . Export::EXPORT_KEY; $grid->setExcelOptions($this->getDefaultExcelOptions()); $grid->exportfile = $this->getExportFileName(); $grid->gSQLMaxRows = Export::EXPORT_MAX_ROWS; // Currently 100000 rows $grid->exportToExcel(); |
So basically it’s pretty simple. I’ve tried with $grid->setColModel($colModel) and it doesn’t make any difference except pdf exports will break if I don’t define it. I tried to check your php code but it’s obfuscated so it’s impossible. Any help will be appreciated.
hello,
The problem is the use of array driver and data. In case of number try to set the values as numbers and not as strings something like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
array( array ( 'AccountName' => 'Example Account #1', 'ProjectName' => 'Amigurumivirkkaus', 'SubprojectName' => 'Virkkausprosessi', 'SubprojectEndDate' => '29.10.2014', 'EstimatedCost' => 100.00, 'ResourcedInvoicing' => 200.00, ), array ( 'AccountName' => 'Example Account #2', 'ProjectName' => '1036', 'SubprojectName' => 'awsdf', 'SubprojectEndDate' => '14.08.2015', 'EstimatedCost' => 200.00, 'ResourcedInvoicing' => 300.00, ), ); |
Regards
Will
Guriddo Support Team
I’ll try tomorrow. I’ve also tested values as float (not strings) but as I remember it didn’t work. So the problem is with the array driver and not the data set or should it work with array driver? Have you documented this somewhere?
Hi,
I tried it and no difference. Still “number” cells are in general format. So I can’t show them in two decimal format. 100.00 will be 100. Yeah sure they are aligned to right. Same happens in your example.
Hello,
We will investigate the problem. Seems the problem is in PHPExcel lib. Will replay ASAP.
Thank you
Kind Regards,
Will
Guriddo Support Team
Hello,
We have investigate the problem deeper. It is a PHPExcel lib default behavior instead that we set explicit the field as number in the code – the field is created as General Number without formatting.
To fix this we have made a decision to set default number formatting (in excel options) and in case there is a need of custom one we will include a special excel formatting in formatoptions array for a particular field.
This all will be available in the next upcoming release October, 2016.
Kind Regards,
Will
Guriddo Support Team
Hello,
we have jqGrid PHP 5.0.0 version and our licence only covers minor updates. Sadly new version, in which this is fixed, is major update and therefore we don’t have access to it.
Isn’t this bug a kind of a bug that should be fixed to older versions too? Since this has been working before and you have decided to use 3rd party library which has this behavior. Now exports doesn’t look like they should and it reduces user experiance significantly.
Hello,
I understand your point and agree with you.
Please write to the support in order to get the fixed update.
Kind Regards,
Hello,
we now have newest version 5.2.0 but we’re still having problems with exports as rapantti stated earlier.
Can you offer example how to work with number fields when exporting to Excel? Earlier Will wrote:
To fix this we have made a decision to set default number formatting (in excel options) and in case there is a need of custom one we will include a special excel formatting in formatoptions array for a particular field.
How is this done, we’ve tried setting formatter to number (which should affect to grid only) and that didn’t do any good.
Does header row somehow affect to column format, if header is text should that set the whole column to string and if so, how can that be changed
Thanks
Seppo
Hello,
Can you please set for us a small example with data of course demonstrating what you want to achieve – i.e what you expect and what is happen?
Thank you
Kind Regards,
Will
Guriddo Support Team
Data
array (
‘Invoicing’ => 1000.01,
‘TargetPricePerHour’ => 1000.01,
)
colmodel
array (
0 =>
array (
‘name’ => ‘Invoicing’,
‘label’ => ‘Laskutus’,
‘formatter’ =>
array (
‘decimalSeparator’ => ‘.’,
‘thousandsSeparator’ => ‘ ‘,
‘decimalPlaces’ => 2,
‘defaultValue’ => ‘0.00’,
),
‘align’ => ‘right’,
‘sorttype’ => ‘numeric’,
),
1 =>
array (
‘name’ => ‘TargetPricePerHour’,
‘label’ => ‘Tavoitehinta / h’,
‘formatter’ =>
array (
‘decimalSeparator’ => ‘.’,
‘thousandsSeparator’ => ‘ ‘,
‘decimalPlaces’ => 2,
‘defaultValue’ => ‘0.00’,
),
‘align’ => ‘right’,
‘sorttype’ => ‘numeric’,
)
Excel options
“file_type”=>”Excel2007”,
“font”=>”Arial”,
“font_size”=>10,
“path_to_phpexcel_class”=>”External/phpexcel/PHPExcel.php”
Code
1 2 3 |
$conn = new \jqGridArray(); $grid = new \jqGridRender($conn); |
1 2 3 |
$grid->setColModel($this->getColModel()); $grid->setExcelOptions([as mentioned above]); |
1 |
$grid->renderGrid('#grid', '#pager', true, null, null, true, true); |
Expecting
Excel with Invoicing and TargetPricePerHour cells to be number with 2 decimals and thousand separator space
Getting
Excel with Invoicing and TargetPricePerHour cells being general format
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top