Copy to clipboard limitation

2019-07-11 15:57发布

As many other question about this topic, I still didn't find something that could avoid my issue.

I'd like to know what are the limitations of the clipboard in term of copy paste processing in time and restrict its copy paste functionality for specific usage and program ID.

Because, I've been developping a software for my company that takes a template in Word/Excel and PowerPoint to make auto generated reports by replacing the picture every day and pasting the new graph and the picture which are in the template.

But, I'm afraid, because it seems to exist some limitations about the copy to clipboard

CopyBitmapToClipboard

ActiveWindow.View.PasteSpecial()

When I copy a table/image into my clipboard and paste it in Word/Excel/PowerPoint it is fine, but if I have now 10 parallel reports which are generated at the same time and use the mechanism of copy paste, it will happen that it will copy it in the Word/Excel/PowerPoint that is currently being used by another report.

Taking in consideration, I have 1 document, and the copy to clipboard of a table that is huge into powerpoint, would take the best case 1 second( which doesn't ), this would mean that in 1 day, I can generate a maximum of

1 copy paste procedure = 1 second

1minute = 60 second means 60 copy paste

1hour = 60min x 60 copy paste

1day = 24hours x 3600 copy paste

Means I have a total of 86400 copy paste/reports. Which is impossible. A document will never take minimum of 1 second to be complete( for reports which are about 20 pages, powerpoint with 30 slides, excel worksheet with 6sheets ). How to avoid that the content copied into clipboard will be pasted in the wrong document, since both documents use the paste fonction.

So, I'd like to know, if it is possible to give a reference into my clipboard, to tell him, to copy only the content inside his word/excel/powerpoint and not to copy what I just copied doing CTRL+C and to do CTRL+V in the wrong document?

At the moment, we have about 50 reports daily to generate( taking in consideration that few months ago we had 2 reports to generate ), which are scheduled in interval of 5 minutes, but what will happen the day we will have 86400 daily reports to generate? The copy paste fonction will screw up all reports and paste in the wrong report. I might not be there to assist it, but I'd like to prevent that impact.

I was writing my software in C#/.NET, but I can't write inside it to catch if a current schedule/report is being generated, because I run a .bat that does the creation of the report with the program I wrote.

**Edited: Content of my .bat is: myprogram.exe /objectsourceprogram="" /sourcefile="my template.doc/xls/ppt" /destinationfile="my destination.doc/xls/ppt"

I'm only scheduling my batch file, the only thing that can be done is, waiting that one scheduling is being completed before starting the next one, but this will create intervales

1条回答
三岁会撩人
2楼-- · 2019-07-11 16:10

I've dealt with auto-generated reports in Word and Excel as well. You're doing it the slow way, no wonder it's slow - .NET COM interop is quite slow as it its and then your process utilizes other threads, so now you have to take marshalling and synchronizing between threads since Office is single-threaded.

Copy/paste is a high-level, user function and you can use it as a hack but relying on it as a primary way of executing your task is a poor choice.

Better choice: Office APIs (VSTO, anyone?) - I'm pretty sure whatever you've come up with in terms of reports is reproducible through APIs. Beware - too many API calls and your functions can work slower.

Best choice: OpenXML SDK. The learning curve here will likely be steep since you're still using Copy/Paste but the payoff is that your document processing time will be reduced a couple orders of magnitude.

查看更多
登录 后发表回答