String from C++ code pasted into Excel has formatting problem
TCHAR text[256];
_stprintf(text, _T("2-4"));
Using code like this I copy 'text' to the clipboard and then paste it into Excel. But Excel interprets "2-4" as February 4th and puts "4-Feb" into the cell.
Is there some way I can format a string so that Excel does not try to do a conversion?
When entering the string directly into Excel typing an apostrophe (') first will work, but from C++ code the apostrophe stays when pasted into the cell.
I have also tried putting quotes around the string - _stprintf(_T("\"2-4\"")) - but that doesn't work either.
Re: String from C++ code pasted into Excel has formatting problem
I'm no expert, but if you're doing this manually, why don't you turn off formatting for the cells that you're going to be pasting data into? Screen-shot attached.
Edit: I think I misread your post.
Edit2: This seems to work:
="2-4"
="2-5"
="2-6"
Last edited by Plasmator; April 17th, 2008 at 12:13 PM.
Re: String from C++ code pasted into Excel has formatting problem
Thanks for the suggestion, but there are several reasons why I want to avoid a solution like that.
First, the data that will be copied is primarily numbers so having them also formatted as text in the spreadsheet will cause another set of problems.
Second, I don't like the idea of telling all of our customers that they have to format the spreadsheet first. From a user's point of view the copy and paste should just work. That's why I am looking for a solution that tags a cell as text at the source (the C++ code).
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.