Copy formatted cell contents from Excel to Word without clipboard - excel

I would like to know if it is possible to transfer the contents of a formatted Excel cell to Word without the use of the clip board.
Using a macro to copy and paste works great - but it interferes with the users clipboard, rendering their PC / Workstation a bit useless.
I have done some background research into a property called WordOpenXML
https://msdn.microsoft.com/en-us/library/microsoft.office.tools.word.document.wordopenxml%28v=vs.120%29.aspx?f=255&MSPPError=-2147217396
My thought process would be to spawn an Excel copy and open the spreadsheet access the inner xml of the Excel cell (or the Open XML) and just set the Property in Word.
That way I know it has transferred like for like - with no use of the clipboard.
Maybe there is another approach - I wondered about spawning a separate clipboard object.

You could try to store what's inside the clipboard in a variable at the beginning of the macro. At the end after your copy/paste action you could restore the clipboard to it's original state.

Related

Copy cells from excel sheet and paste it to a DB query Sikuli

I am new to Sikuli. I need to copy data from excel sheets and paste them to a DB query using sikuli script. And how can I iterate among the excel cells to copy and paste the data repeatedly.
These data needs to copied and pasted one after the other.
It might be easier to copy all of the cells at once, then paste them one by one.
once Sikuli has opened Excel, you could do something like:
type(Key.HOME, KeyModifier.CTRL) #takes you to cell A1
type("a", KeyModifier.CTRL) #select all
type("c", KeyModifier.CTRL) #copy to clipboard
fromExcel = Env.GetClipboard().strip() #get clipboard contents into Sikuli, without leading or trailing white space
cells = fromExcel.split("/n") #split each cell into list on newline
#go to the destination app, maybe using App.open("nameOfYourApp") if it's not open yet, or App.focus("nameOfYourApp") if it is already open
for cell in cells: #use python to iterate through your list
#navigate to the line or cell where you want to paste
paste(cell)
Would something like that be of help?
Rather than providing a specific approach let's understand the options you have.
Simulate user keyboard actions (like it is described here by #autoKarma).
Excel sheet having a very specific structure allows you to detect some key points like first column and first row and then calculate other cells locations based on them.
You can try and use one of the Python Excel API libraries to access the excel sheet directly via API. If you only need to read the document and to to amend it, I believe this will be fairly easy to do.
Note: In all cases you will obviously have to think of how do you bring yourself to the point where you have an open Excel sheet on your screen and how to dispose of it when done.

Pasting charts from Excel with large files

I am having trouble when pasting some charts (not as a picture) from Excel into powerpoint. The problem is that the file is very large and a powerpoint which should be roughly, 200kb is around 20MB.
I was wondering if there was a way around this whereby you could paste it, but not as a picture?
You need to use Special Paste, and paste as Microsoft Graphic Object
(if you want to be able to edit it, i.e. change font, sizes, ...).
If you use the regular paste , it'll be linked and with embedded data, that is why it is so heavy!
Regretably, you canNOT change the default paste option in powerpoint like it possible in ms-word...

Issue with Copying Excel Cells

I am not sure if there is a solution to this issue. In Excel when you copy a cell the border starts moving/flashing. Only when that border is moving you are allowed to paste its contents into another cell. Once the border is no longer moving, you are also unable to paste its contents. The other option is to double click on the cell or go into the formula bar to manually copy the data, which then you can paste as much as you want, at least until something else is copied.
Here is my problem. I have script within the “Private Sub Worksheet_SelectionChange(ByVal Target As Range)” section of my worksheet. So every time another cell is selected this script is run. The script works perfectly and I do not need this changed. The spreadsheet first needs to be unlocked before the script can run, so I had to put this at the top of the script “ActiveSheet.Unprotect” and this at the bottom “ActiveSheet.Protect”. When I select a different cell and the code hits either the unprotect or the protect commands, then the copied cell border is no longer flashing, so I can’t paste.
Is there a script of some sort that I can use so it retains the copied data? The script should only run when a cell is copied. I also don’t want to use the SendKeys function because that typically causes more issues then what it solves. I have always been wondering where Excel stores its data for copied cells, since usually copied data is stored in the windows clipboard, or some other dumping ground since Windows 7 & 8 no longer use the clipboard for copping data. So I don’t understand why Excel doesn’t use the same method as everything else when a cell is copied.
This isn’t too much of an issue, more of an annoyance than anything. If someone should have a solution to this please let me know, but I don’t think there is one.

How to copy from Excel to Word without using the clipboard?

I've written a C# application that copies cell ranges of an Excel workbook as images in a Microsoft Word document, using the Excel.Range.CopyPicture or Excel.Range.Copy methods.
But processing big Excel files can take time, and if the user uses the Clipboard in an other application during the process, my application can crash.
I'm wondering if there is a way to copy Excel cell ranges as images in a Word document without using the clipboard, to avoid this kind of issues.
Thanks for your help,
Julien
There is a solution, I have used ages ago:
Copy the data to a new worksheet and save that worksheet as a pdf, in turn, extract the picture from the pdf and than save that picture as a new file. in Word, use the addpicture method to load the file from disk...
Very clumsy, but it is reliable....
What about copying the image to the clipboard like you're doing, but then immediately saving that image as an image in your code? That way, you can still use your old procedures and store the image internally - no longer having any dependancy on the clipboard.
I did the exact same thing in a question I asked just earlier this week - Look at my posted solution:
Control Excel Within WebBrowser Control
Just use the image as needed now that you have it stored internally and set it to nothing as soon as you can to save on memory.
Hope this helps

Copy SYLK formatted text to clipboard from HTA

I'd like to programmatically copy tabular data (both formatting and formulas) to the clipboard from an HTA (HTML Application), to paste into Excel. Excel supports a text format called SYLK for accomplishing this task, but I've run into a snag with over-validation in window.clipboardData.setData(format, data) where format is restricted to either "Text" or "URL", giving the error "Unexpected call to method or property access" if format is set to anything else, and Excel only recognizes SYLK text if format is set to "SYLK", otherwise it pastes as normal text.
I'm wondering if there's another way to set clipboard data from an HTA, such as through a COM control that comes preinstalled with either Windows or Office, that would let me copy SYLK data to the clipboard.
I know I could write a custom COM control and install it on each client, but at that point I might be better off just writing to a file and opening the file instead of using the clipboard.

Resources