Bug 77317

Summary: EDITING: ' prepended when applying Number or Scientific format to Text formatted cell with a number in it
Product: LibreOffice Reporter: Michael Doube <michael>
Component: SpreadsheetAssignee: Not Assigned <libreoffice-bugs>
Status: RESOLVED NOTABUG QA Contact:
Severity: enhancement    
Priority: lowest CC: christopher.m.penalver, jmadero.dev, mariosv
Version: 3.5.7.2 release   
Hardware: x86-64 (AMD64)   
OS: Linux (All)   
See Also: https://launchpad.net/bugs/1305877
Whiteboard:
i915 platform: i915 features:
Attachments: Sample file linking data in a web page

Description Michael Doube 2014-04-11 09:08:15 UTC
This is a simple bug in Calc which can be replicated by doing the following:

1. Set a cell format to Text
2. enter a numerical value into the cell (e.g. 1 or 1E1)
3. Set the cell format to Number or Scientific
4. Note that the cell data is left justified and has a ' prepended to it in the input line, which is not visible in the cell itself

This means that the cell value still interpreted as text and not as a number, so it's impossible to plot it in a chart or do arithmetic with it.

I hit this the first time when copying some data from a website into Calc. The numerical values were not recognised and were automatially pasted into Text formatted cells (OK, that's understandable). BUT: changing the values to Number or Scientific format didn't change the underlying datatype of the cell from characters to numbers.
Comment 1 Michael Doube 2014-04-11 09:08:54 UTC
Downstream bug report:
https://bugs.launchpad.net/ubuntu/+source/libreoffice/+bug/1305877
Comment 2 Eike Rathke 2014-04-11 10:08:10 UTC
That's not a bug. Applying a cell format never changes the cell content. The ' apostrophe in the input line is prepended so that when editing the content it stays text. Removing the ' will accept the input as number then. You can bulk change multiple cells by selecting them, apply a number format and then invoke Find&Replace   Search: ^.   Replace: $0   and in options check regular expression and selection only. Or use the Convert-Text-To-Number extension from http://extensions.libreoffice.org/extension-center/ct2n-convert-text-to-number-and-dates
Comment 3 Michael Doube 2014-04-11 10:24:08 UTC
For the record I'd like to note that this is a bizarre, unintuitive intended behaviour, and the fix you propose is equally bizarre and unintuitive. Having to install an extension seems way over the top for what should be a core functionality (I guess at some point someone was so desperate to do this that they resorted to coding the extension!).

I first attempted a find-replace for ' -> [empty], which didn't work. Your regex example will be totally opaque to nearly all users.

The answer to the pasting some data from a website problem is to Paste Special... get the delimiters right and make sure to check the box to detect special numbers (my data are here: http://physics.nist.gov/PhysRefData/XrayMassCoef/ComTab/pyrex.html ).
Comment 4 m.a.riosv 2014-04-11 22:15:19 UTC
Hi Michael, even you don't like how it works, it is not a bug as Eike have explained, and he knows, as expert developer, about what he is talking.

Changing the cell format never change their content, unintuitive or not, this is a basic assumption in a spreadsheet, and I hope this will be always so.

If there are not formulas, you can copy the range and select the unformatted text option in the right arrow of the paste button. 
Or if it is only a column with data using Menu/Data/Text to columns.

If you are not agree, please open a new bug as a request for enhancement, detailing as much as possible what you want.

Next comment I attach a file sample how to extract the data from your web page, throuhg Menu/Insert/Link to external data.
You can see and edit the link in Menu/Edit/Links.
Comment 5 m.a.riosv 2014-04-11 22:16:16 UTC
Created attachment 97240 [details]
Sample file linking data in a web page
Comment 6 Christopher M. Penalver 2014-04-12 17:17:31 UTC
Eike Rathke, thanks for taking a quick look at this.

Given when one comes from using Excel, where if one converted the Category from a Text to a Number, no apostrophe is appended, and how the LO code had designed an apostrophe in, this would be an "Excel functionality compatibility expectations" report. Hence, would the WORKAROUND you documented in https://bugs.freedesktop.org/show_bug.cgi?id=77317#c2 be documented on the LO wiki at http://help.libreoffice.org/Main_Page ?

m.a.riosv, suggesting the original reporter create now a third report (one downstream, this one, and your suggested third) because they didn't know it's an enhancement vs. a bug is a terrible habit of the OpenOffice.org bugzilla I've seen happen to others and personally experienced, and that we here at LibreOffice would not want to replicate.

Hence, I've gone ahead and marked this lowest enhancement given the advised WORKAROUNDs.

Thank you for your understanding.
Comment 7 Michael Doube 2014-04-14 14:34:39 UTC
Dear Eike, m.a.risov and Christopher,

Thanks for taking your time with this.

As a programmer concerned about user experience (which sometimes I get to practise, when not battling with spreadsheets), the userland behaviour is pretty weird. Why is there an apostrophe in the input line and not in the cell? That breaks all my assumptions about the relationship between the input line and the cell. For example, if I enter a ' into the input line, when a Text formatted cell is selected, I get a ' in the cell. Suddenly making a ' appear in the input line without it being in the cell is strange. Current behaviour seems like a cheap hack to get out of doing some actual conversion logic and user interaction. e.g.

1. Cell chars are all numerals, looks like an integer, no problem -> integer
2. Cell chars might look like a decimal number maybe with a , or a . or an E: ask the user what to do (locale-dependent sensible default required)
3. Function text is included (e.g. =, SUM(A1:A10), etc.) if it parses, -> no problem
4. Something else is there, random text, whatever. Then just apply number format to the cell and behave as though the user typed the same string of chars into the cell.

I hope that you can see that these solutions are, from a user perspective, somewhat more appealing than the current behaviour which is something like:

prepend a ', but only display it in the input line and not in the cell. Don't warn the user that this has happened because of an unwillingness to change the underlying datatype of the cell. Also don't tell them that they have to apply an obscure, terse regex to get rid of the ' and make the data how they want it: let them try to find it on the wiki (assumes motivation and a working internet connection). Allow them to waste their time working out how to reenter their data / figure out the correct combination of copy-paste options.
Comment 8 Joel Madero 2014-11-06 00:11:13 UTC
Moving to UNCONFIRMED to get QA team to look at it - very likely it's closed again but looking for additional feedback. Thanks for your patience and understanding.
Comment 9 Joel Madero 2014-11-06 00:12:42 UTC
Nevermind I just reread this - it's not a bug, please don't reopen it. For additional info you can check out this extension: http://extensions.libreoffice.org/extension-center/ct2n-convert-text-to-number-and-dates

Again - please don't reopen this. Bringing in that extension into core is already reported as an enhancement request.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.