Have created a Gtk "calculator" that has a spreadsheet-like element (similar to and partially based on GtkSheet
/GtkExtra
). It is capable of, amongst other things, using the usual Ctrl-X/C and Ctrl-V to Cut/Copy/Paste data/strings within itself, and also across to other apps, such as Excel/OpenOffice etc (i.e. in both directions) using GtkClipboard
elements.
For example, it can also perform Cut/Copy/Past of ranges (though via a different route, and this in not in Python) discussed in this SO posting.
However, when an Excel, OpenOffice, etc cell contains a formula (and displays the formula's value ... eg. formula in cell =1+2, displays 3), copying the Cell into the proprietary Gtk-Spreadsheet via GtkClipboard
only pastes/contains the "display value" (not the formula).
How does one get GtkClipboard
to pass the formula instead? Does this require some GDKAtom
specification, is it necessary to use gtk_clipboard_request_text()
vs. _request_content()
etc. and work through the "(Gtk) target", or ???
P.S. Copying, say, an Excel cell (with formula) to, say, an OpenOffice cell works correctly in that OO will contain the formula and display the result (though we cannot be certain if the formula is contained in the OS's clipboard, or if OO et al. are doing something extra). Is it presumptuous to imagine that GtkClipboard
should be able to do it as well ... ?
UPDATE: Since the Original Post (OP), we have followed-up with some testing to further assess our "intuition" that perhaps the GtkClipboard
or the Windows clipboard, or some combination therein, may not be capable of directly passing spreadsheet formulas (or "full" Cell contents) via Cut/Copy/Paste (CCP). Here are some results:
1) We tried to look at the OO, POI, etc source code to see how they do it, but it's much too big. We tried to look at GNumerics source code, but from our perspective, it uses a coding style that is much too difficult (at least for us) to follow.
2) So, we performed a few additional test to see if we could determine at least the possibility of relying on the OS/GtkClipboard
. During these tests we also "kept an eye" on the Windows clipboard via clipbrd.exe (the Windows clipboard viewer (WCV)):
a) As before, when CCP from Excel to OO (and both apps are simultaneous running), everything is passed.
Though, WCV only shows the display value, not the formula or any other property of the cell (e.g. colours, etc)[Note: WCV can pass some colours etc if an image format is used, but not the explicit Cell "contents/formulas/properties" etc]. This is a bit worrying for Gtk, as it implies the passing of the formula etc is not actually via the (basic OS) clipboard.
b) When CCP in reverse, from OO to Excel (with both apps running), it does NOT work, only the display value is passed (no formula's, properties, etc).
Again, a bit worrying with respect to (wrt) GtkClipboard
possibilities.
c) When the Copy is performed from Excel, but before OO is launched, and then Excel is closed, and the Paste after OO launched, it does NOT work for formula's etc, only the display value.
Again, a bit worrying wrt GtkClipboard
possibilities.
d) Skipping some details to avoid diluting this point, our sense is that the (only) "successful" CCP (from Excel to OO while both are running) is somehow performed with some combination of OO accessing the OfficeClipoard (c.f. the Win clipboard, which Gtk has access to) and/or using some ODBC/OLE or whatever direct internal connection to Excel to effect the passing of the full Cell contents. That the CCP does not work in reverse (i.e. OO -> Excel), or only when both are running, also supports this contention.
Although these tests/results do not in themselves decisively prove that the OS/GtkClipboard
is not actually usable for CCP of "full" Cell/Range contents, they are highly suggestive of that. However, for all we know, there may be some GtkClipboard
(GdkAtom
etc) settings that might permit access to other (e.g. Office) clipboards, but we can't find any info on this.
Similarly, it would be useful to know if anybody has succeeded in CCP'ing these sort of things in a Unix/Linux environment with Gtk (we are testing via a couple different MingW setups on Win, but the Win and Office clipboards seem to have some difference under Gtk compared to under Linux).
... as such, we would be grateful to anybody with actual knowledge on the subject at least to confirm whether or not the Win/GtkClipboard
strategy is a waste of time, and if not, any hints for implementation would be much appreciated.