How to programmatically Paste CSV text into Excel and not just go into one cell? (C++) - c++

I have a list/grid in an MFC (c++) application. I would like the user to be able to copy and paste the data into a spreadsheet.
I've placed the data in the clipboard and the text makes it to the clipboard ok and I can paste it to notepad or Word or Excel, but Excel does not interpret the comma separated value-ness of my clipboard content - so it just goes into one cell/one column - rather than doing what I had hoped.
I hope there is something simple I am missing.
Any suggestions to get this to work?
I am not quite ready to make this a drag/drop source (which is in the task list)
EDIT:
I have it working - commas can't be used - must be tab separators
But now there is a new problem:
The issue now is that if I paste to excel using '\n' as line separator it looks good in excel but not in notepad.
If I make it "\r\n" then notepad looks correct but excel then has blank lines.
Any suggestions on how to make both consistent?

I used this question and tabs seem to work - but csv still does not
How to paste CSV data to Windows Clipboard with C#

Well, here's my two cents..
It seems a tab character in an NSString, such as #"123\t456" would tell Numbers and OpenOffice spreadsheets, that 456 goes into the next cell of the same row.
Likewise, a newline character \n, or a carriage return \r, would put follow-up data on a new row, for example #"123\n456" or #"123\r456" would put 456 in the next row (starting with the first column from the left).
Indeed, TextEdit does not interpret the newline (\n) or carriage return (\r). (OpenOffice text documents do.)
However, providing the pasteboard with an array of strings (be it NSStringPBoardType, or NSRTFPBoardType, or whatever), puts the different strings on seperate rows, both in a spreadsheet and in TextEdit.
Also, a tab (\t) shows up as a tab in TextEdit, which you can then manipulate in the toolbar, to get a nice layout of your data.

Related

handling the UTF 8 characters in apex

I have created a textarea pageitem. In the textarea, I am pasting a sql query or writing a simple text with space and linebreak . On submit, in the next page , the same needs to be displayed.
As my sql query or the inputted text was getting displayed in same line without linebreak, I used the below code. Which solved the problem.
:P2_NEW := replace(replace(:P2_NEW,CHR(32),' '),chr(10),'');
htp.p(P2_NEW);
But now when i copy the sql and try to run in sql developer, the sql doesnt run, On pasting the sql in notepad ++ and selecting encoding->UTF8, i am seeing that whereever there is space, it is getting replaced as 'xA0' characters Similarly for text which contained ü is replaced by 'xFC'.
What needs to be done so that, the space doesnot get replaced by xA0 and ü by xFC(Please note there are many similar characters that gets replaced with the corresponding UTF8 characters.eg ä)
Please advice.

Google Apps Script - ReplaceText vertical tab

Whenever I paste text into a Google Docs document, all the newline characters get convereted into vertical tab characters (\013 OR \v). This happens regardless of the source of the clipboard text (webpage, word, notepad++).
Usually this means I have to work my way through the document clearing all the vertical tabs and replacing them with proper newlines by backspacing the character and hitting return. However, I want to write a script to replace all the characters in the doc at once. The Replace ui feature doesn't support newline characters but I'm hoping the scripting api does.
I have written the code below, but though it runs, the vertical tab characters are not replaced. I can still see hundreds in the document with the find/replace ui feature. What am I doing wrong?
function myFunction() {
var body = DocumentApp.getActiveDocument().getBody();
body.replaceText("\\v", "\n");
}

How to keep the view format in notepad++ from simple notepad?

Been trying to get this one done for some time and couldn't find a solution.
The annoying issue I got is that when I open my x.txt notepad file everything is in line, organized, well arranged however when I do open it with notepad++ everything gets messed up. Here is a quick example (left notepad++/right notepad, same file) http://prntscr.com/9ypxcm
Some of the files get the same view format and style in both notepad and notepad++ (probably they were created originally in notepad++?) however some of my other text documents get really messed into notepad++ and I just hate simple windows notepad when it comes to text editing.
Would appreciate some help. Thank you
I just checked for How much spaces does a tab takes in both ?.
Notepad++ takes 4 spaces to constitute 1 tab.
Windows Notepad takes 6 spaces to constitute 1 tab.
Therefore when a file which is first edited in Windows Notepad ( 6 spaces-tab ) is opened in Notepad++, the tab is converted to 4 spaces reducing 2 spaces. That's why everything gets messed up
Solution
1) This is same file opened in two editors.
2) Now go as directed
Settings --> Preferences --> Tab Settings --> normal.
Uncheck the Use default value.
Click on Tab size. A small input box will appear.Input 6 as value and press Enter.
3) The tabs are now properly formatted.

How to prevent OpenOffice/LibreOffice Calc from changing what you input (data, numbers,...)

Basically, I want LibreOffice Calc to do what I tell it, not what it wants.
For example:
when I input 1.1.12, I want to have 1.1.12 in that cell, not 01.01.2012 or whatever.
when I input 001, I want to have 001 in that cell, not 1
and so on and so forth
I want it to never ever touch my data until I explicitly tell it to. Is that possible at all?
I know I can set format of a cell to text. It doesn't help at all. Example:
Input 1.1.12, it gets displayed as 01.01.12, format as text, it becomes "40909", original input is lost
Format empty cells as text. Paste "000 001 002 ..." separated by line breaks. Displays "0 1 2 ..."
I know I can write ' in front of anything for it to be forced text. Again it doesn't help, because when I paste in text, I cannot have ' auto-appended to it.
I hope this is possible. I tried googling for different problems and never found a good answer.
If you want your input to be interpreted as text and preventing Calc to do fancy (and annoying) things with your input, you have to change the format before entering any value.
Select the cells/columns/rows.
Right-click 'Format Cells...'
Select the tab 'Numbers'
In the list 'Category', select 'Text' (the last option)
Select the format '#' (it is the only one in this category)
Click on 'Ok'
You may need to tweak the 'autocorrect' options as well. Go to 'Tools > Auotcorrect Options...'. Here is a link that may help: https://help.libreoffice.org/Calc/Deactivating_Automatic_Changes
I understand your problem with pasting pure unformatted text. This may be more work than you like (we can try to automate that later) but when I paste data from Notepad, I am prompted with an import screen as you can see below. Select the column header(s) and then select Column type: Text. This should solve your paste/import problem. An alternative is to handle this with an AutoHotKey script.
Oh b.t.w. the # is the format type for text, just like you have HH for 24 hour or ddd for weekdays...
When you are importing, you're given a bunch of options. Select "Quoted field as text" so any text inside quotes is treated as text which is interpreted by LibreOffice as sacred and they do not modify it in the way they they modify something that they identify as number
When you have your data in the clipboard click Edit -> Paste as... in main menu. In next window choose "Paste as text". All your data will be pasted as is.
I initially arrived at this page with a very similar (but not identical) problem. I am posting the solution here for the benefit of those who might be visiting with the same issue.
Every time I would save, close, and then re-open my .XSLX spreadsheet in OpenOffice, it would delete the spaces I had entered in between text. For example:
"Did not attend" would become "Didnotattend".
"John DOE" would become "JohnDOE", etc.
Specifying "text" (#) as the format (as recommended above) did not help me, unfortunately.
What ultimately did solve it was saving it as an .ODS file instead of .XSLX .
just simply put character ' before the text, '0.1.16 and calc will interprate it as text data
My issue was currency, properly formatted would change to a much larger number if the numbers entered could represent a date; such as 4.22 becoming $42,482. I discovered that adding a trailing zero solved the problem.
I had pasted numbers from another site and it kept coming up with dates. I just messed around and hit the arrow that's on the paste board to give me the option of unformatted text or HTML format. I selected unformatted, a window opened to show me the text I wanted so I pressed o.k.

Copying numbered lists from a RichEdit?

When you send a WM_COPY message to a RichEdit control having a numbered list selected,
and then paste the text into Notepad, the numbers are not included. Is there any way to get them?
Thanks!
You don't get the numbered list because Notepad does not support text formatting such as bullets, bold, numbering etc.
The target application must support rich text. Copying from RichEdit and pasting in Wordpad, MS Word, Html Editor works well.
Thanks.