Comments (11)
@renciebautista, can you please give me more details on what the error is exactly? Are you writing a CSV or XLSX file?
from spout.
Hello.
I insert the following data:
The format of the cell must be numeric, but it turns out a text.
from spout.
Tested and verified. If anyone wants to give a try fixing that one, please do so :) I'll be happy to help!
from spout.
@renciebautista, @anmoroz, can you please give me more info on how this is problematic for you?
By default, values are treated as numbers so "Standard" actually means "number" (int or float). Also, if you read the generated file, it will give you a float back, not a string.
from spout.
I need to add pivot table, which is located in a separate file. But pivot table is destroyed
For standard cell type, I can not use the formula without conversion.
I have studied the documentation of Microsoft - seem your code is correct. But the data in the cell is not a number.
I do not know what the problem.
from spout.
You should be able to use standard cells as numeric values without any conversion. This is what happens when you manually create an Excel spreadsheet and don't specify the cell format. You can also use pivot table without specifying the cell format.
I think that your problem is not linked to this. By the way, I'm not sure how you create you pivot table but this is not supported by Spout. Closing this issue as it's not a actual issue.
from spout.
Facing this same issue. Spout will prefix ' to the number in xlsx (when I open the file in LibreOffice, it shows this character. In excel, it adds the green flag to the top left corner of the cell. When we remove the ' and save the file, Excel correctly formats the cell as a number). Nothing related to pivoting. This is just a general issue.
from spout.
We found a solution for this. In the WriterEntityFactory.php, in the createRowFromArray() fn, we added a check for is_numeric and casted numbers to doubles.
So the updated function looks like this now:
public static function createRowFromArray(array $cellValues = [], Style $rowStyle = null) {
$cells = array_map(function ($cellValue) {
/**
* Cast the $cellValue to the correct type based on the value
*/
if (is_numeric($cellValue)) {
$cellValue = (double) $cellValue;
}
return new Cell($cellValue);
}, $cellValues);
return new Row($cells, $rowStyle);
}
from spout.
The deeper issue is here:
public static function isNumeric($value)
{
$valueType = gettype($value);
return ($valueType === 'integer' || $valueType === 'double');
}
The CellTypeHelper strictly checks that numbers are only ints and doubles.
This should be updated to the simple:
public static function isNumeric($value)
{
return is_numeric($value);
}
from spout.
I think the initial code was what you proposed but it was changed to checking type directly. While using is_numeric
works for your use case, it breaks other cases (I think some people expect "123"
to not be numeric but a string.
from spout.
isNumeric() should mean is_numeric.. I don't see why outputting "123" (string) as 123 (number) in xslx would cause some people's excels to break.
from spout.
Related Issues (20)
- Thanks to package authors! How does it work? HOT 1
- Style not present when editing existing spreadsheet
- It takes around 5 secs to read 1000 rows (25 cols) HOT 1
- This page isn’t working when calling $reader = ReaderEntityFactory:: HOT 1
- Previous issue #861 prematurely closed HOT 4
- Support Excel cell Comments HOT 2
- Unable to open source data
- Trying to add vertical alignment and fix textWrap for XLSXWriter HOT 1
- Add option to change the encoding of the whole exported csv file (not only the content) HOT 1
- PHP 8.1 Error HOT 4
- Incorrect type reported when adding an unsupported type to a cell
- Percentage type reading supported? HOT 1
- Content-Disposition header for file download is not properly encoded HOT 1
- Format date on export XLSX
- Is it possible to use wb instead of wb+ fopen mode in openToFile() in AbstractWriter in order to use compress.zlib:// ? HOT 5
- PHP 8.1 Warnings HOT 2
- Doing cell->getValue() on loop stops when the value is a DateTime Object
- rowIterator->next() crash HOT 5
- rowIterator->next()
- Count total number of rows for XLSX HOT 1
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 spout.