I generate an Excel file with importing a csv file. In CSV has contents with following numbers
4.0238484
5.3833888
dot seperated
But if I write an Excel file than the column show me the numbers in following format
4,0238484
5,3833888
I want the dot instead of comma.
How can I make it?
PHPExcel Version 1.7.7
In PhpSpreadsheet (next generation of PhpExcel) you can avoid it's by this:
$sheet->setCellValueExplicitByColumnAndRow(__COL_INDEX__, __ROW_INDEX__, __SOME_DATA__, DataType::TYPE_STRING);
setCellValueExplicitByColumnAndRow can force turn your data into string
Check the locale settings for the version of MS Excel that you are using to view the generated file: if it's set to a locale that uses a decimal comma rather than a decimal point, then this is what you will see. Floating point numbers in PHPExcel are managed with a decimal point (PHP doesn't offer any alternative for numbers), but MS Excel has its own formatting rules based on locale.
Related
I have a issue with data formats of Excel and SQL.
I have a column in SQL which is of datatype DECIMAL(18,0) and when I am trying to paste the result in SQL..the last 3 digits of the sql result gets replaced by 0 in Excel.
Example:
In SQL the result set has a column called session id and has decimal numbers like
119,597,417,242,309,670
329,621,151,415,350,454
134,460,940,261,658,890
but when I paste it in Excel the numbers look like:
I tried changing the format in EXCEL to paste as text however, the whole format of the result set gets distorted (and only the first column gets pasted properly without the 0's)
I can't keep casting all columns in SQL from decimal to int as there are way too many columns.
Can you please guide me as to what I can do?
Numeric fields in Excel are limited to 15 digits precision.
In SQL Assistant under Tools / Options / Data Format you can ask to have large Decimal (and BIGINT) fields displayed as text for just this sort of copy / paste. Or you can tell SQL Assistant to Save As or Export to Excel format.
For other tools you can explicitly FORMAT and CAST the data to VARCHAR in your SELECT so it is retrieved as text.
Several things you can do. I'll list 4.
Pick whatever suits you best.
First paste in a text editor (like notepad), seach/replace there, and paste that.
Set the datarange where you're going to paste to "text", and then paste. After that you can search/replace, and change to the correct format.
Change the regional settings of Windows to match the data that you have.
You can generate formula's from your SQL query, instead of floating point numbers. So generate a text like =5/10 instead of 0.5 or 0,5. Excel will pick it up correctly regardless of your regional settings.
Im exporting an excel file into a .csv file (cause I want to import it into R) but R doesn't recognize it.
I think this is because when I open it in notepad I get:
Item;Description
1;ja
2;ne
While a file which does not have any import issues is structured like this in notepad:
"Item","Description"
"1","ja"
"2","ne"
Does anybody know how I can either export it from excel in the right format or import a csv file with ";" seperator into R.
It's easy to deal with semicolon-delimited files; you can use read.csv2() instead of read.csv() (although be aware this will also use comma as the decimal separator character!), or specify sep=";".
Sorry to ask, but did you try reading ?read.csv ? The relevant information is in there, although it might admittedly be a little overwhelming/hard to sort out if you're new to R:
sep: the field separator character. Values on each line of the
file are separated by this character. If ‘sep = ""’ (the
default for ‘read.table’) the separator is ‘white space’,
that is one or more spaces, tabs, newlines or carriage
returns.
I should read data from more than 4 different excel file with different cell formating but same data within, so how i can change the cell format then read the data using phpexcel?
If you're storing a numeric value that's longer than a 32-bit signed integer can handle (such as 435546567567345) then treat it as a string using
$objPHPExcel->getActiveSheet()
->setCellValueExplicit(
'A1',
'435546567567345',
PHPExcel_Cell_DataType::TYPE_STRING
)
EDIT
If you're reading this value from an Excel worksheet, and it is actually a number value rather than a string containing a numeric value, then it is likely being treated as a float by MS Excel, so there may well be some loss of precision already (unless the file was created using a 64-bit version of MS Excel), even before PHPExcel reads it. If it is a number created using a 64-bit version of MS Excel, then you'll need a 64-bit version of PHP to read it without loss of precision.
Try reading the raw, unformatted value using getValue() and then doing a var_dump() to see what datatype it actually is; or try using getDataType() to see what the value was being stored as in the Excel file
I'm working with PHPExcel and I'm trying to format a cell using Excel's built-in "Accounting" format. I'm aware of the Format Code:
PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE
But this simply formats to two decimal places and adds a $ in front of the number. The result I'm looking for is the right aligned cell with the $ on the left. $0 values should be listed as "-" and negative values should be $ (1.11)
As far as I can tell there are no other currency formats in the documentation (though I may have missed it, this documentation is horrendous). Am I looking in the wrong place? Can this be achieved with regular cell formatting or is Excel doing something unique for Accounting?
I reverse engineered the format code from an existing spreadsheet using PHPExcel and got this:
_("$"* #,##0.00_);_("$"* \(#,##0.00\);_("$"* "-"??_);_(#_)
This is the code Excel places on the cell when you select the "Accounting" format... or click that "$" toolbar button in Excel 2007.
If you didn't need currency symbol :
->setFormatCode("_(* #,##0.00_);_(* \(#,##0.00\);_(* \"-\"??_);_(#_)");
$objPHPExcel->getActiveSheet()->getStyle('C1')->getNumberFormat()->setFormatCode("#,##0.00");
or use
$objPHPExcel->getActiveSheet()->getStyle('C1')->getNumberFormat()->setFormatCode("#.##0,00");
Set in getStyle CELL.
There are no other pre-defined formats beyond those listed in PHPExcel_Style_NumberFormat, but you should be able to set the format code to any string that you could use when setting an MS Excel custom format...
e.g.
[green]$#,##0.00;[red]$(-#,##0.00)
As regards cell alignment, set this to right yourself, or don't set it at all.
I imported TSV files using Firefox SQLite Manager but the decimal separator is comma and math functions are ignoring the decimal part of the value. Could you help me?
Thank you
I haven't used Firefox SQLite but I have used SQLiteman and with this GUI was a problem work with comma as decimal mark (if your database is light perhaps you can 'replace' those commas using an spreadsheet or something like that...). In my case, as my database was really large, the solution was use the raw SQLite shell: I imported perfectly a csv file (separated by ;) with commas as decimal mark. Additionally, the importing process was faster. Cheers.