Comments (9)
Which writer do you use ?
from phpexcel.
I instanciate the PHPExcel_Writer_Excel2007 writer
from phpexcel.
This was certainly true for 1.7.7, but I've already fixed this issue on the develop branch here on github.
Using the following code to try and replicate your problem:
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setCellValue('A1', '0.25');
$objPHPExcel->getActiveSheet()->getStyle('A1')
->getNumberFormat()
->setFormatCode(
PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00
);
$objConditional1 = new PHPExcel_Style_Conditional();
$objConditional1->setConditionType(PHPExcel_Style_Conditional::CONDITION_CELLIS)
->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_LESSTHAN)
->addCondition('0');
$objConditional1->getStyle()->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_RED);
$objConditional2 = new PHPExcel_Style_Conditional();
$objConditional2->setConditionType(PHPExcel_Style_Conditional::CONDITION_CELLIS)
->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_GREATERTHANOREQUAL)
->addCondition('0');
$objConditional2->getStyle()->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_GREEN);
$conditionalStyles = $objPHPExcel->getActiveSheet()->getStyle('A1')->getConditionalStyles();
array_push($conditionalStyles, $objConditional1);
array_push($conditionalStyles, $objConditional2);
$objPHPExcel->getActiveSheet()->getStyle('A1')->setConditionalStyles($conditionalStyles);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
This works correctly: both the conditional background colour and the number format styles are maintained when the spreadsheet is saved. As I'm unable to replicate this issue, can you please upload a sample code that demonstrates your problem to the phpexcel.codeplex.com site.
from phpexcel.
Hi Mark, sorry about the long silence, my boss need my help on other work...
Anyway, i'm back for this issue.
I try your code but i get an error : Class PHPExcelIOFactory not found.
I download the last commit on dev branch but i can't find any classe named PHPExcelIOFactory.
Where do i lost myself ?
When i use 1.7.7 writer style call :
$writer = new PHPExcel_Writer_Excel2007($objPHPExcel);
header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition:inline;filename=Fichier.xlsx ');
$writer->save('php://output');
I still get the original issue. bug seems to be fix on the writer.
Regards,
ajouno
from phpexcel.
The PHPExcel_IOFactory class is in the file IOFactory.php in the /Classes/PHPExcel directory.... if your script can't find that, then something is very, very wrong indeed... like the PHPExcel code is missing or not defined in the path (though I'd expect PHPExcel.php to be problematic as well if that was the case)
from phpexcel.
oh crap...
I just copy your code without my brain...
I copy from the email which contain :
$objWriter = PHPExcelIOFactory::createWriter($objPHPExcel, 'Excel2007');
and not this :
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
"_" change all...
So i can try your code.
Thanks
from phpexcel.
I try your code and get the same issue as before.
A1 get a green color font with 0,25 in cell
when i select A1, the value in fx box is 25%
To get A1 with 25% display i need to get in conditionnal cell
edit the rule to add pourcent format with color font condition.
I can send you the xls file if you want.
Maybe an issue with european office 2007 ?
from phpexcel.
I've done !
// ############################ this don't work ############################
// style define
$conditionOK = array( 'numberFormat' => array( 'code' => PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00),
'fill' => array( 'type' => PHPExcel_Style_Fill::FILL_SOLID,
'startcolor' => array('rgb' => '00FF00'),
'endcolor' => array('rgb' => '00FF00') ));
// style apply
$objConditional1 = new PHPExcel_Style_Conditional();
$objConditional1->setConditionType(PHPExcel_Style_Conditional::CONDITION_CELLIS);
$objConditional1->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_LESSTHAN);
$objConditional1->addCondition('0');
$objConditional1->getStyle()->applyFromArray($conditionNOK);
// ############################ this don't work ############################
// ############################ this work ################################
$objConditional1->setConditionType(PHPExcel_Style_Conditional::CONDITION_CELLIS)->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_LESSTHAN)->addCondition('0');
$objConditional1->getStyle()->getFill()->getStartColor()->setRGB('FF0000');
$objConditional1->getStyle()->getFill()->getEndColor()->setRGB('FF0000');
$objConditional1->getStyle()->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objConditional1->getStyle()->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00);
// ############################ this work ################################
issu seems to come from "applyFromArray" method.
Thanks for your attention.
Regards,
Aymeric
from phpexcel.
Hi,
I have the same problem with 1.7.9 and the git develop branch. Tested with my code as well as Mark's code from above.
Basically, if you don't explicitly specify a number format in the conditional style array PHPExcel will always use "General". That means all cells that match the rule will be formated as General independent of what the original cell format is. Ajouno's solution of explicitly setting the format isn't really an option for me, because my conditional format spans multiple columns with different number formats.
As far as I can tell the problem is in Style/NumberFormat.php lines 202-214: public function setFormatCode, which sets the number format to "General" if none is specified.
I tested it by commenting line 205 and the result is what I expected. If no format is specified then no format is applied and all cells preserve their original formating. But this does cause some PHP warnings down the line, specifically in the function getHashCode() line 366 of the same file.
EDIT: I just realized I also had to explicitly set the conditional number format to null, otherwise it doesn't work.
I hope this help you fix this issue.
from phpexcel.
Related Issues (20)
- Is it possible to use php send excel files to client's printer?
- Php Excel fails at load
- Font Style existed but not visible
- exception 'directory'yii\base\ErrorException' with message 'ZipArchive::close(): Failure to create temporary file: No such file
- Syntax error
- An implementation cannot be declared in ambient contexts.
- Setting workbook password does not seem to work at all
- Can't export any excel
- "Excel cannot open the file 'filename.xlsx' because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file. HOT 2
- How can I open the encrypted file?
- Install pathing not working HOT 1
- Do you have a simplified version of PHPExcel?
- Double include PHPExcel_Cell::stringFromColumnIndex function
- PHPExcel_Worksheet_Drawing
- PHP Excel 1.8.2 Loss of precision when writing numeric strings
- Fatal error: Missing function on 1.8.2
- 发现内容部分有错误 HOT 1
- Set document properties with UTF-8 Encoding (for accents)
- read csv with long number data get scientific notation
- export Excel with formulas
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phpexcel.