Load Excel add-in - excel

I tried:
$sAddIn = "H:\prog\essxleqd.xla"
$oExcel = ObjCreate("Excel.Application")
$oExcel.Visible = 1
$oExcel.WorkBooks.Add
$oAddIn = $oExcel.AddIns.Add($sAddIn)
$oAddIn.Installed = True
$oExcel.WorkBooks.Open("H:\Balance_Inquiry.xls")
When I do:
Run('"c:\pathtoexcel\excel.exe" "c:\pathtoaddin\addin.xla"')
It will work. But I prefer the former solution because I need two different add-ins.
$sAddIn = "H:\prog\essxleqd.xla"
$oExcel = ObjCreate("Excel.Application")
$oExcel.Visible = 1
$oExcel.WorkBooks.Add
$oAddIn = $oExcel.AddIns.Add($sAddIn)
$oAddIn.Installed = False
$oAddIn.Installed = True
$oExcel.WorkBooks.Open("H:\Balance_Inquiry.xls")
This seems to do the trick. First time it got installed and worked. Afterwards it didn't. Even when it is installed it doesn't execute the second time. Maybe someone can explain or provide a more elegant solution?

Strange problem indeed. It seems that the addon will only do its operations when you install it? That is not how Excel addons should behave, and that is why you are seeing strange behavior when trying to automate it.
If the addon needs to be reinstalled to work, then indeed the only solution is to reinstall the addon.
$oAddIn.Installed = False
$oAddIn.Installed = True
If this is an addon that is written by you or someone in your own business, then you might want to identify the problem in the addon itself. I can safely assure you that the normal mode of operation works well. :))
As a bonus tip, you might want to do this:
$oAddIn = $oExcel.AddIns.Add($sAddIn, True)
It will copy the file to the appropriate location if that is necessary, otherwise it is left alone.

Related

Deleting trail/retain of a moving displayObject

How do you delete a trail from a moving object (the trail exists out of points)?
I thought that if you,
sphere.retain = 0
sphere.make_trail = False
It would instantly delete the trail. But this ins't true because if you put a:
sleep(50)
after it. You can see that the trail is still there.
Setting s.make_trail = False just means "stop adding points to the trail".
In GlowScript VPython or Jupyter VPython you can say s.clear_trail().
In Classic VPython, s.trail_object is the curve or points object, and you can delete elements of these objects.

too much error correction made the code more worse

This is my first time with python and I have written this program to simulate a node trying to find mobile phones in an area.
first i am taking the distance converting them to RSS and based on that deciding the direction of the node to find all mobile phones.
the code worked fine till 2 days ago but when i expanded to area and no of nodes, some errors started to come and i kept correcting them.
now it doesn't run and I have made it more worse:
is there any hint or guidance I can get from the experts?
and yes I have overwritten the code without saving it to some other place.
Or maybe someone can really help me by having a look at it.
its really messy though.
thanks
Here is a part of the code i am having the most trouble with.
def pos_y(uav_current_cord,area,uav_step_size,flag):
detected_y = 0
detected_nodes_pos_y = 0
if flag == 1:
span = area+uav_step_size - uav_current_cord[1]
#print(span)
for y in range(uav_current_cord[1],area+uav_step_size,uav_step_size):
global distance_covered
distance_covered += uav_step_size
UAV_new = [uav_current_cord[0],y]
y_last_pos = UAV_new
plot((*UAV_new), marker='o', color='r', ls='')
distance_new=[]
for i in nodes:
temp_x_axis = euclid_dist(UAV_new,node_cord[i])
ss_x_axis = dist_to_ss(temp_x_axis)
if (ss_x_axis > threshold):
detected_nodes_pos_y += 1
detected_y = (detected_nodes_pos_y)
if y >= area+uav_step_size:
uav_current_cord = UAV_new
flag = 1
keep_moving = neg_x(uav_current_cord,span,uav_step_size,flag,y_last_pos)
uav_current_new = keep_moving[0]
distance_covered_back = keep_moving[1]
nodes_detected_final = keep_moving[2]
uav_current_new = keep_moving[3]
#return [uav_current_new, distance_covered, nodes_detected_final, uav_current_new]
#uav_current_new = y_last_pos
return [y_last_pos, distance_covered, detected_y, y_last_pos]
if flag == 1:
area1 = area*2
for y in range(uav_current_cord[1],area,uav_step_size):
UAV_new = [uav_current_cord[0],y]
#print('Pos_Y movement of UAV',UAV_new)
#print('ye loop chal raha hai')
y_last_pos = UAV_new
plot((*UAV_new), marker='o', color='g', ls='')
distance_new=[]
for i in nodes:
temp_x_axis = euclid_dist(UAV_new,node_cord[i])
ss_x_axis = dist_to_ss(temp_x_axis)
if (ss_x_axis > threshold):
detected_nodes_pos_y += 1
detected_y = (detected_nodes_pos_y)
#print('nodes detected in pos Y ',detected_y)
#print('last position in pos y =', y_last_pos)
for y in range(UAV_new[1],uav_current_cord[1],-uav_step_size):
# print('ab ye chala hai')
UAV_new=[uav_current_cord[0],y]
plot((*UAV_new), marker='o', color='g', ls='')
distance_covered_back = area*2
return [UAV_new, distance_covered_back, detected_y, y_last_pos]
As others have said, use git, but know the alternatives.
If you're brand new to revision control, starting with Git will either be a big help or hindrance in the time being, but learning Git will be valuable down the line regardless.
If you have an MSDN account, you can also use Visual Studio's built-in revision control. It's good for rapid prototyping, but has no real edge over git.
Another common choice that is pretty simple would be TortoiseSVN. It's very easy to use.
Alternatively, if you don't mind your code being public for a free account or a small monthly fee for private, you can do all your commits via browser using GitHub. This is hand's down the simplest option for revision control newbies. It's major downside is limited flexibility for multi-file commits.
I have little to no meaningful experience with BitBucket and some other common alternatives to GitHub.
I'm sorry, but we cannot help you... You're not the first with this problem and unfortunately not the last.
To help prevent this kind of problems, software like Git exists. It let's you do the following (image reference):
The root file is the master. This is your working script. If you want to change/add/remove something, you make a so-called branch where you do whatever you want. If you have tested it, you can commit the changes (that is, store this as a new version of the script with a comment) and merge it with the master (that is, add the changes to the master script). If something seems to be wrong, you can always go back to a previous version of your script.
The documentation of Git is very good: read it and use it wisely!

Crystal Report 7 Alternate Row Color

I'm trying to make a report by using Crystal Report 7. But I'm having trouble when I tried to make the odd detail become white and the even detail become gray
Here what I've tried
I'm waiting for the answer. Thx
even though it's an old post, maybe some people still need it. I happen to still use cr 7, I use this logic and this works fine.
if right(totext(recordnumber / 2),2) = '00' then White else Black
if right(totext(recordnumber / 2),2) = '00' then true else false
Take a look at this link, this might help you.
http://victoriayudin.com/2009/03/31/alternating-shading-for-lines-in-crystal-reports/
OR
Try this:
if RecordNumber mod 2 = 0 then crWhite else crSilver.

Why does this snippet for fallback-sourcing a mixed list of Puppet templates/files not work?

This seems to sit between the domains of stackoverflow and serverfault, but it seems ultimately a devel issue, so am posting it here.
In order to make my Puppet tree a bit more DRY (while avoiding enormous if-else ladders and hacky "/dev/null" fallbacks in my manifests), I want to be able to just call a function with a mixed list of templates/files to lookup in order, and use (and expand if necessary) the first one found. I wrote the code below heavily based on some ancient code (see the commented line for the link to that). I can't see why it doesn't yet work, and would appreciate if anyone can find what I've missed (or misunderstood).
I am ensuring:
Apache (and Passenger sub-process) are restarted on the master (to pick up the new function) before running puppet on the client
the client is run with --pluginsync
and I have already unsuccessfully tried:
using wrapper.file = filepath instead of wrapper.file = filename
and many other things, which I won't list as they seemed to have been red herrings. I found one email-thread which hinted that such code would only run on the client, whereas it of course needs to run on the master, but I can see the original code from the pastie link has worked successfully for others, and my changes shouldn't make any difference to the client/master aspect of that.
I am running puppet v3.7 on the client and v2.7 on the master (long story short - I can't avoid this for now, (see EDIT3 below) but I think the important point is that they are both >= 2.6, regarding the environment.to_s change).
I call the function with:
$sshd_config_content = multi_source_mixed("template|ssh/sshd_config.${::fqdn}.erb", "file|ssh/sshd_config.${::fqdn}", "template|ssh/sshd_config.${::domain}.erb", "file|ssh/sshd_config.${::domain}", "template|ssh/sshd_config.${::hostname}.erb", "file|ssh/sshd_config.${::hostname}", 'template|ssh/sshd_config.erb', 'file|ssh/sshd_config')
and always get the error:
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: multi_source_mixed: No match found for files/templates: template|ssh/sshd_config.XXX.erb, file|ssh/sshd_config.XXX, template|ssh/sshd_config.XX.erb, file|ssh/sshd_config.XX, template|ssh/sshd_config.X.erb, file|ssh/sshd_config.X, template|ssh/sshd_config.erb, file|ssh/sshd_config at /etc/puppet/environments/YYYY/modules/ZZZZ/manifests/init.pp:337 on node XXX
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
My code (so far) is:
# adapted from template-only version at http://pastie.org/666728
# this doesn't yet work (for me)
module Puppet::Parser::Functions
require 'erb'
newfunction(:multi_source_mixed, :type => :rvalue) do |args|
this_module = 'THIS_MODULE_NAME'
contents = nil
environment = compiler.environment.to_s
sources = args
sources.each do |file|
if file.index('|')
filetype, filename = file.split('|', 2)
else
filetype = 'file'
filename = file
end
Puppet.debug("Looking for #{filetype} #{filename} in #{environment}")
if filetype == 'template'
if filepath = Puppet::Parser::Files.find_template(filename, environment)
wrapper = Puppet::Parser::TemplateWrapper.new(self)
wrapper.file = filename
begin
contents = wrapper.result
rescue => detail
raise Puppet::ParseError, "Failed to parse template %s: %s" % [filename, detail]
end
break
end
else
filepath = Puppet::Module.find(this_module, environment).to_s + '/files/' + filename
if File.file?(filepath)
begin
contents = File.open(filepath, "rb").read
rescue => detail
raise Puppet::ParseError, "Failed to get contents from file %s: %s" % [filename, detail]
end
end
break
end
end
if contents == nil
raise Puppet::ParseError, "multi_source_mixed: No match found for files/templates: #{sources.join(', ')}"
end
contents
end
end
EDIT: BTW - I know the files being sourced exist in the right place already, as what I am doing with this code is replacing existing code which has been working already, but is hardcoded to search for files only, using the following:
source => ["puppet:///modules/ZZZZ/ssh/sshd_config.${::fqdn}", "puppet:///modules/ZZZZ/ssh/sshd_config.${::domain}", "puppet:///modules/ZZZZ/ssh/sshd_config.${::hostname}", 'puppet:///modules/ZZZZ/ssh/sshd_config']
EDIT 2: I proceeded with trying to test this using client=3.7 and master=2.7 because it is the only setup I can use for now, but I have since found several threads stating that it is painful-and-usually-impossible to even try to get an older puppetmaster version to cooperate with a newer puppetclient version, and I know at least one of the errors I've been ignoring for now has been to do with that. I suspect even some of this specific problem may be a consequence of that too, but unfortunately have no easy way to test things further until the upgrade of the master happens (probably won't happen for at least a week or two) (see below)
EDIT 3: I am now testing it with client and master at v2.7, and the problem remains...

Java clipboard not working

I was trying to copy an image to the clipboard and paste it into gimp with this code snippet:
BufferedImage bi = new BufferedImage(board.getAmount()*16,16,BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = bi.createGraphics();
Color[] colors = board.getColors();
for (int loop = 0; loop < board.getAmount(); loop++) {
g2d.setColor(colors[loop]);
g2d.fill(new Rectangle(16*loop,0,16,16));
}
ImageSelection is = new ImageSelection(bi);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(is, null);
Anyways in theory everything should have worked out fine. It gave me no errors, but when I try to paste the image, nothing happens.
This was done on two different linux machines and neither worked. I then came to school and tried it out with the same code on Windows and it worked.
So I guess my real question is does it have something to do with open-jdk, or java 1.7, or is it linux's problem? And how can I fix it?
I think the next page could be useful: http://www.java2s.com/Code/Java/2D-Graphics-GUI/SendingImageObjectsthroughtheClipboard.htm.
Consider the following lines to copy the image to the clipboard.
final Clipboard clipboard = frame.getToolkit().getSystemClipboard();
label.setTransferHandler(new ImageSelection());
...
TransferHandler handler = label.getTransferHandler();
handler.exportToClipboard(label, clipboard, TransferHandler.COPY);
I had the same problem, and found this to work:
final Clipboard clipboard = frame.getToolkit().getSystemSelection();
...then continue using that as a regular clipboard. The "system selection" allows you to change what the window manager thinks is selected, and is therefore "on the clipboard".
I'm not sure what the best way to detect whether system selection or system clipboard should be used, but it looks like Windows will return null for getSystemSelection, so that can be used as a test.

Resources