How to remove a plain text protecting single quote from all the selected cells in LibreOffice Calc?

36

20

I've imported a CSV file having the first column to be date-time values in ISO 8601 format like

2012-01-01T00:00:00.000Z

for the first moment of the year 2012.

Then, willing to make LibreOffice to recognize the format (as I was looking forward to plot a diagram), I've selected the column, chosen Format Cells... and entered the custom time format as

YYYY-MM-DDTHH:MM:SS.000Z

And this seems to work if... I edit a cell to remove a hidden single-quote from its beginning (which serves to protect a cell content from being interpreted) as all the newly formatted cells now store values like

'2012-01-01T00:00:00.000Z

(note the single quote - it is only visible when you edit a particular cell).

And I am to do so for all the cells in the column. How can I automate this?

UPDATE: I've already found a solution for the particular case of mine: it helps to set a column format to "time" in the CSV import dialogue. But I am still curious how could this be done in case I wouldn't have the original .csv data file to import but only the .ods file with the data already imported without the format specified at the import time.

Ivan

Posted 2012-02-26T01:46:08.000

Reputation: 6 173

Answers

52

You can remove the leading single quote (which actually isn't part of the string in the cell) using a regex-based search and replace:

  • Search for all characters between the start and end of the string ^.*$
  • replace with match &

tohuwawohu

Posted 2012-02-26T01:46:08.000

Reputation: 8 627

2Thank you. This is so weird, it beggars belief. Why on earth there should be this single quote character after importing? – r0berts – 2015-05-16T13:47:10.210

Please, developers: do not "fix" this "feature" :) – fbicknel – 2019-03-22T17:35:32.800

4Thank heavens for the internet and for you, sir. This was exactly right. – queso – 2012-03-05T21:44:19.320

5How the heck does it work if it even has no actual quote symbol (nor its code) in it? – Ivan – 2012-03-26T00:03:24.467

5@ivan - It's a messy hack, but it doesn't actually replace the quote at all. Basically, from the regex engine's perspective, the quote isn't there at all (it's a special flag on the cell). As such, what it does is match the entire contents of the cell (which doesn't have the quote in the string, remember). Then, what it does is delete the cell contents (which includes clearing the "plain text" flag), and then reinsert the contents. The data autodetection engine then sees a number, and interprets the reinserted data as such. – Fake Name – 2013-06-05T22:10:06.917

It's worth noting that this will probably delete any formatting that relies on characters that set special cell flags, as well as the "plain-text" number flags. – Fake Name – 2013-06-05T22:10:48.490

30

From the "Data" menu, choose "Text to columns".

pfrenssen

Posted 2012-02-26T01:46:08.000

Reputation: 481

5A cleaner alternative to the REGEXP method. – jgomo3 – 2014-06-22T19:03:15.377

Crucially, the "Text to columns" function allows altering the "type" of the cells. Sometimes it's stuck on "text" and no amount of re-formatting seems to fix it. Here's how: at the bottom of the dialog box under "Fields", click the column header which says "Standard", then select the desired type in the "Column type" drop-down. – sxc731 – 2016-12-01T12:53:18.957

The Regex didn't work in LibraOffice, but change the column type to "Text" from "Standard" using Text to Columns worked. – Exit – 2018-05-24T07:35:50.743

Scratch that, as soon as I try to style the column as a number with 8 decimals, it adds the single quotes back in front. I give up, returning to Excel. – Exit – 2018-05-24T07:41:22.483

0

An attempt for regex replacing of ^.\*$ with & crashed LibreOffice 5. Replacing of .\* with & worked fine.

VMT

Posted 2012-02-26T01:46:08.000

Reputation: 1

-1

By the use of a little computer formatting and search magic trick (programing technique if you will) called a Regular Expression or regex for short. For examples please see - http://www.regular-expressions.info/examples.html

Steve

Posted 2012-02-26T01:46:08.000

Reputation: 1

3you would be a cool dude if you could write an example regex. – Mikhail – 2012-11-03T11:47:12.683

-2

Actually, you need a to quote the dollar sign first.

Basically libreOffice is prepending a single quote in the field, for some unknown reason. So, you need to replace anything up to the dollar sign with nothing. So, use the regex of ^.*\$ and replace it with nothing. Worked for me.

Andrew B.

Posted 2012-02-26T01:46:08.000

Reputation: 1

What dollar sign are you talking about? – Scott – 2013-12-04T22:36:58.363