Copy report pasteboard

I want to copy the report to the pasteboard, then modify some attributes, and then paste it back, because too many of the same attributes need to be modified in batches. The following is the method I found, but it does not work

def addURLToClipboardObject(url):
	from java.awt import Toolkit
	from java.awt.datatransfer import DataFlavor, Transferable
	from java.io import ByteArrayInputStream
	from java.lang import String
	import re
	
	class MockReportMillClipboard(Transferable):
		RMDataFlavor = DataFlavor("application/reportmill", "ReportMill Shape Data")
		def __init__(self, data):
			self.data = String(data).getBytes()
		
		def isDataFlavorSupported(self, flavor):
			return flavor == self.RMDataFlavor
		
		def getTransferData(self, flavor):
			if flavor == self.RMDataFlavor:
				return ByteArrayInputStream(self.data)
	        
	clip = Toolkit.getDefaultToolkit().getSystemClipboard()
	
	dataflavor = None
	for df in clip.getAvailableDataFlavors():
		if df.mimeType == 'application/x-java-serialized-object; class=java.lang.String':
			dataflavor = df
			break
	if df:
		data = clip.getData(dataflavor)
		regex = r"<text(.*)>"
		subst = r'<text\g<1> url="%s">' % url
		result = re.sub(regex, subst, data, re.MULTILINE)
		print "Added URL to clipboard object"
		clip.setContents(MockReportMillClipboard(result), None)

hellow

That’s not much information about your problem. Paul’s really good at this stuff, but I don’t think he reads minds yet.

3 Likes

I want to copy the report and batch modify some of the same properties on other editors, such as adjusting the width to 5, selecting all, and replacing them instead of modifying them one by one. Paste the modified ones back, instead of modifying them one by one in the original report

The technique in the original post would need significant changes to work for ‘batch’ processing. You’re on your own :slight_smile:

Oh, is there anything to share

	dataflavor = None
	for df in clip.getAvailableDataFlavors():
		if df.mimeType == 'application/x-java-serialized-object; class=java.lang.String':
			dataflavor = df
			break
	if df:
		data = clip.getData(dataflavor)
		regex = r"<text(.*)>"
		subst = r'<text\g<1> url="%s">' % url
		result = re.sub(regex, subst, data, re.MULTILINE)
		print "Added URL to clipboard object"
		clip.setContents(MockReportMillClipboard(result), None)

The important piece is this. It does naive regex replacement to modify the XML representation you get out of reportmill. If you multi-select your elements and then paste into a text editor, you can see that same representation. You can parse and manipulate that tree accordingly, and then use the MockReportMillClipboard class to, as the name implies, mock the ‘real’ ReportMill Transferable class - that way it will paste back into the reporting workspace as ‘real’ objects.

Thank you very much, you are so amazing