Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
Packages and Libraries
»
FPSpreadsheet
»
Copy to clipboard and paste in Excel
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
IRC channel
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
Parameter passing odditie...
by
ASerge
[
Today
at 09:42:03 pm]
fkInternalCalc
by
zraja
[
Today
at 09:31:07 pm]
A fairly simple sound sol...
by
KodeZwerg
[
Today
at 09:23:37 pm]
Demo Scene Picture sinwav...
by
Gigatron
[
Today
at 09:00:25 pm]
add new targets to make
by
marcov
[
Today
at 08:38:42 pm]
how to tweek fpmake to co...
by
marcov
[
Today
at 08:29:16 pm]
Quirky windows
by
ASerge
[
Today
at 07:07:16 pm]
[Request] Demo Scene Sub ...
by
Gigatron
[
Today
at 06:29:39 pm]
Unlocking Files
by
KodeZwerg
[
Today
at 06:03:08 pm]
[SOLVED] trunk bug for mi...
by
Key-Real
[
Today
at 05:56:32 pm]
Demo Scene Bitmap Font Sc...
by
Gigatron
[
Today
at 05:56:27 pm]
Compile/Convert Delphi pr...
by
Martin_fr
[
Today
at 05:43:11 pm]
Generics - correct syntax
by
Thaddy
[
Today
at 05:40:59 pm]
Lazarus for Windows on aa...
by
msintle
[
Today
at 05:32:42 pm]
InstallAware Using Lazaru...
by
msintle
[
Today
at 05:26:36 pm]
Xcode Command Line Tools ...
by
Joseph
[
Today
at 05:16:39 pm]
Offical launch of the 1 B...
by
Hartmut
[
Today
at 04:49:29 pm]
what to do if my target M...
by
nickysn
[
Today
at 04:16:02 pm]
compiler error in unit
by
paule32
[
Today
at 03:49:50 pm]
Can function be used for ...
by
VisualLab
[
Today
at 02:15:30 pm]
Multithreading - synchron...
by
mika
[
Today
at 01:48:51 pm]
May be useful to somebody
by
KodeZwerg
[
Today
at 12:38:22 pm]
match automatic highlight...
by
Чебурашка
[
Today
at 11:35:14 am]
Tchart with dual numbers ...
by
wp
[
Today
at 10:48:18 am]
Debugger crashes with App...
by
Martin_fr
[
Today
at 09:29:46 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Copy to clipboard and paste in Excel (Read 5786 times)
vertnik
New Member
Posts: 31
Copy to clipboard and paste in Excel
«
on:
October 01, 2018, 03:03:21 pm »
Hy!
I have a question about possibility of coping the worksheet content into Windows clipboard and
paste it to Microsoft Excel?
I found the following routine CopyToClipboardStream, but I am not sure if this procedure can do that?
Thanks,
Robert
Logged
wp
Hero Member
Posts: 11923
Re: Copy to clipboard and paste in Excel
«
Reply #1 on:
October 01, 2018, 03:08:51 pm »
I suppose you have your data in a Worksheet Grid. Then simply select the range to be copied and press CTRL+C to copy the cells to the clipboard. In Excel click at the top-left cell of the range to which the copied cells should go and press CTRL+V.
Logged
vertnik
New Member
Posts: 31
Re: Copy to clipboard and paste in Excel
«
Reply #2 on:
October 01, 2018, 08:43:10 pm »
No, i create workbook and worksheet at run-time. Than fill some cells with writetext routine.
Robert
Logged
wp
Hero Member
Posts: 11923
Re: Copy to clipboard and paste in Excel
«
Reply #3 on:
October 01, 2018, 09:35:42 pm »
You can extract the pretty much self-contained procedure TsWorkbookSource.CopyCellsToClipboard from unit fpspreadsheetctrls and you only must register the clipboard formats.
Note that I was not able so far to write the xlsx and ods formats to the clipboard. But the old xls format is working and can be read by Excel and LibreOffice Calc (and other programs); and for the few other programs which do not understand xls, the routine also writes the worksheet selection as HTML and CSV.
In the attachment there is an example which contains everything (tested).
Logged
vertnik
New Member
Posts: 31
Re: Copy to clipboard and paste in Excel
«
Reply #4 on:
October 02, 2018, 11:10:18 am »
Thank you wp,
paste in Excel works for HTML, CSV and text formats. But the problem is
for sfExcel5 and sfExcel8 formats. When use paste, Excel returns "Microsoft Excel cannot paste the data."
However, using html format looks just fine.
Robert
Logged
wp
Hero Member
Posts: 11923
Re: Copy to clipboard and paste in Excel
«
Reply #5 on:
October 02, 2018, 11:19:51 am »
Strange... I tested with Excel 2016, and when I wrote the clipboard support I had Excel 2007 - both of them accept the xls formats in the clipboard. Is there a configuration issue? What is your Exel and Windows version?
Logged
vertnik
New Member
Posts: 31
Re: Copy to clipboard and paste in Excel
«
Reply #6 on:
October 02, 2018, 11:34:43 am »
Windows 8.1
Excel 2010
Logged
wp
Hero Member
Posts: 11923
Re: Copy to clipboard and paste in Excel
«
Reply #7 on:
October 02, 2018, 01:35:56 pm »
I also have Excel97 on a VM with Windows 2000, and it also behaves correctly. So, I think that, in general, clipboard should work for xls for "all" Excel and Windows versions. But there are some xls features which fpspreadsheet does not support or maybe are not written correctly so that Excel refuses to load the stream (
http://wiki.lazarus.freepascal.org/FPSpreadsheet#Progress_by_supported_cell_content
).
Does my demo posted above already have the xls issues for you? Your answer was not specific on this aspect.
What exactly is the cell content/formatting that you copy to the clipboard when the xls issue happens? Images? Comments? Hyperlinks?
The structure of the data copied to the clipboard is exactly the same as in a written xls file. So, just to make sure, please save the spreadsheet to xls format (sfExel8 or sfExcel5) and post the file here for me to have a closer look (or if you don't want to publish it send me a PM and I can give you my e-mail address)
Logged
vertnik
New Member
Posts: 31
Re: Copy to clipboard and paste in Excel
«
Reply #8 on:
October 02, 2018, 02:52:48 pm »
I just run your demo you posted, where you put all format variants of copytoclipboard procedure. When I use the line
CopyToClipboard(stream, sfExcel8, cfBiff8Format);
I got the error in Excel.
Logged
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
Packages and Libraries
»
FPSpreadsheet
»
Copy to clipboard and paste in Excel
TinyPortal
© 2005-2018