Ask Your Question
0

pasting spreadsheet data without linefeed at end

asked 2015-02-10 16:03:04 +0200

dwlamb gravatar image

Is there a method to paste spreadsheet data so there is no carriage return or line-feed at the end of the string?

I have tried using SUBSTITUTE and TRIM to no avail. I really need a method so the copied data is clean when pasted in an application or a little symbol appears signifying an uninterpreted character(s) is/are present

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted
0

answered 2015-02-11 02:06:09 +0200

karolus gravatar image

updated 2015-02-11 02:16:36 +0200

With python and installed 3rd-party-modul pyperclip →→....pip3 install pyperclip --user

import pyperclip as clipboard
newstring = clipboard.paste().strip()

# maybe do something more here with newstring
# eg: newstring = newstring.replace('\n', '\t')

clipboard.copy(newstring)
edit flag offensive delete link more

Comments

I don't think the original poster described the problem precisely enough. This is an issue for me, so let me be specific.

Let's say I have a Calc spreadsheet with a cell that contains "one two three". In WIndows, if I copy from that cell and paste it into a single-line edit control in another app, I get "one two three" and nothing else. Perfect.

But if I perform that same operation on Linux, what the app gets is "one two three\n". There is a newline appended to the string. You don't actually see "\n", of course, you see whatever U+000A happens to display in whatever font is being used. In my case, it's the square box with 000A laid out in a 2x2 grid.

Clipboard handling in X has always been problematic. It's not impossible that this is a Linux problem, but ...(plus)

timrprobocom gravatar imagetimrprobocom ( 2020-06-26 20:47:53 +0200 )edit

Quoting @timrprobocom: " In WIndows, if I copy from that cell and paste it into a single-line edit control in another app, I get one two three and nothing else."
This is how I see it:
It's an obligation of the clipboard in cooperation with LibreOffice (for Copy) and the "other app" (for Paste) to negotiate the flavors. Then the clibboard needs to correctly take what LibO offers, and to answer the request.
Quoting @timrprobocom: "But if I perform that same operation on Linux, what the app gets is one two three\n." What Linux? What clipboard manager?(, what other app. what kind of edit control?)

Lupp gravatar imageLupp ( 2020-06-26 21:26:09 +0200 )edit

By the way: The "answer" here wasn't an answer to the question. This Q&A software has the tool add comment for comments on (probably enhamcements to) questions and already posted answers.

Lupp gravatar imageLupp ( 2020-06-26 21:30:36 +0200 )edit

I'm not using a clipboard manager, so it's the stock X handling, unless xfce4 gets involved. I'm pasting into a GTK text control in a wxWidgets application on Ubuntu 18.04. Mostly, I'm not sure all of that is relevant anymore. There was a time when the Unix world was fragmented enough that one could deflect such issues, but these days text cut-and-paste shouldn't require any thought.

timrprobocom gravatar imagetimrprobocom ( 2020-06-26 22:07:01 +0200 )edit

I posted into this old thread more than 5 years ago, and was therefore notified about the new post.
Contributors knowing your situation better from their own experience may miss this discussion.
You should probably start a new thread.

Lupp gravatar imageLupp ( 2020-06-26 23:09:41 +0200 )edit

In Windows 10 2004, LO 6.4.4.2 Copying 3 cells and pasting into Notepad I get a return after the paste. From Excel 2010 I get a return after the paste in Notepad. If I paste from either spreadsheet into Writer I get a return after the paste. If I paste special into Writer as Unformatted text then I don't get a return.

It looks like it might be there for compatibility with Excel and might have something to do with Word needing a return after a table. No help for you I'm afraid unless you want to make a macro. Somebody has made one for Excel apparently, https://www.extendoffice.com/document...

Earnest Al gravatar imageEarnest Al ( 2020-06-27 11:12:50 +0200 )edit
0

answered 2015-02-10 21:03:29 +0200

dwlamb gravatar image

I do not want to paste into a cell or anywhere in LibreOffice. I want to paste from my spreadsheet into another application where paste special is not available.

edit flag offensive delete link more

Comments

Suppose you are working on Windows. A 'Copy/Paste' of contents from one application into another one has to use the clipboard. LibreOffice neither knowing the capabilities of the target application nor having full power over the clipboard cannot offer what you want, I think.

Lupp gravatar imageLupp ( 2015-02-10 23:03:10 +0200 )edit
0

answered 2015-02-10 16:35:17 +0200

Lupp gravatar image

updated 2015-02-10 23:23:26 +0200

What's spreadsheet data?

Copied from multiple cells, you will always get a new paragraph shifting from one cell to the next one. Copying from one cell and inserting by 'Paste Special' as 'unformatted text' you will not get a NewParagraph inserted.

==== Editing with regard to the questioner's comments. ==== Any application accepting text from the clipboard will have to insert it on its own responsibility. LibreOffice cannot even prevent a substitution of any "u" by an "x" if the accepting software is programmed to do that.

If you want no (or as few as possible) line breaks (may also be NewParagraph) you first must prevent Calc from exporting them. To achieve this you should assemble the content of as many cells as possible by formulae, suppressing internal LineFeeds and simply inserting a space between the contents of two subsequent cells. This can never be done for more than 65536 characters at a time which is the maximum a single cell can contain. As Calc does not offer a range concatenation, more detailed advice will depend on the details of the task (How many cells, how much text per cell and in total ...).

Hope someone else has better ideas.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2015-02-10 16:03:04 +0200

Seen: 1,013 times

Last updated: Jun 26