I try to copy and paste from file to another in Excel with this code:
from win32com import client
xlapp = client.Dispatch("excel.application")
work = xlapp.Workbooks
copysheet = work.Open("D:/mm/trn files/Field Inspection Test Notification for
ERC Review (CI).xlsx" )
cs = copysheet.Worksheets(1)
cs.Visible = 1
cs.Range("B2:G66").Copy()
pastesheet = work.Open("D:/mm/trn files/Field Inspection Test Notification
for ERC Review (ss).xlsx")
pastesheet.Paste(cs.Range("B2:G66"))
But it gives me this error:
raise AttributeError("'%s' object has no attribute '%s'" % (repr(self), attr))
AttributeError: '<win32com.gen_py.Microsoft Excel 15.0 Object Library._Workbook instance at 0x47919440>' object has no attribute 'Paste'
And I don't know what's the problem. Do you have any idea?
The pastesheet is a Workbook object, which does not have a Paste method. You might do something similar to what you did with the copysheet object.
i.e.
ps = pastesheet.Worksheets(1)
ps.Paste(cs.Range("B2:G66"))
Related
I am attempting to get the string descriptor of the Endpoint attribute bmAttributes. I am able to get the value using pyusb but not the string descriptor for it. When i do i get that error.
dev = usb.core.find(idVendor = 0x0126)
dev.set_configuration()
cfg = dev.get_active_configuration()
intf = cfg[(0,0)]
ep = intf[0]
bmattrib = usb.util.get_string(ep, ep.bmAttributes) <--Where error is
I can get the value but not the string. Anyone know how to get this to work?
I am trying to allow a user to upload files to a server from a form, and then display images from my website. The script is Python, which also interfaces to MySQL via cursor.execute commands. I can upload text form fields, but not the file contents, similar to the problem reported at:
uploading html files and using python
I can upload the selected file name, but not read it; I get a read error.
My code is:
#!/home2/snowbear/python/Python-2.7.2/python
import cgi
# Import smtplib for the actual sending function.
import smtplib
import shutil
import datetime
import os
import sys, traceback, re
# Helps troubleshoot python script.
import cgitb; cgitb.enable()
# Import mysql database program.
import mysql.connector
# Windows needs stdio set for binary mode.
try:
import msvcrt
msvcrt.setmode (0, os.O_BINARY) # stdin = 0
msvcrt.setmode (1, os.O_BINARY) # stdout = 1
except ImportError:
message = "No Windows msvcrt to import"
pass
print '<form name="PB_Form" action="PB_resubmit.py" method="post" enctype="multipart/form-data">'
...
# Get form values.
...
if form.has_key("filePix1") and form["filePix1"].value != "":
txtImage1 = form['filePix1'].value
fileItem1 = form['filePix1']
if not fileItem1.file:
print "<br><center>No fileItem1: %s</center>" % fileItem1
else:
data = fileItem1.file.read()
objFile = open(txtImage1, "w+")
objFile.write(data)
objFile.close()
else:
newImage1 = False
...
I get an error for the line:
data = fileItem1.file.read()
The error is:
<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'read'
args = ("'NoneType' object has no attribute 'read'",)
message = "'NoneType' object has no attribute 'read'"
Although "fileitem1" is a proper handle to the file entered into the form, since I can get the file name, it however, does not have a "read attribute," as specified in the error message.
I'm using Bluehost for my server. Could the file-read attribute be turned off by the server, or am I missing something, such as another special import for handling files?
Thanks for any suggestions, Walter
&&&&&&&&&&&&&&&&
New note:
The problem was that form['filePix1'] "file" and "filename" attributes were missing; only the "value" attribute existed, and this would only produce the file name, not the file contents.
With much experimenting, I discovered that the browser, Sea Monkey, is causing the problem of missing attributes. When I used Firefox, the "file," "filename," and "value" attributes were normal. I have no idea why Sea Monkey doesn't support file loading attributes.
Walter
I'm new to python. I'm trying to unzip a file in my current script directory but I can't get this work...
zip = zipfile.ZipFile(os.getcwd() + '/Sample_APE_File.zip')
zip.extractall(os.getcwd())
Error: AttributeError: 'str' object has no attribute 'getcwd'
You assigned a string value to os, it is no longer bound to the module:
os = 'some string'
Rename that to something else.
I am trying to read image from url and save it to model. but i am getting this error message:
AttributeError: addinfourl instance has no attribute '__committed'
this is my code:
location = Location()
location.save()
image = urllib.urlopen(img_url)
location.locations_image.create(bild=image)
I guess, i am doing something wrong while reading an image file from url. can someone pls guide me? thanks a lot
As per the Title, when I run the below code in Python 2.6 I get the below error on line:
print range.Address(RowAbsolute=False,
ColumnAbsolute=False)"
I know what the error means but the MSDN page (http://msdn.microsoft.com/en-us/library/aa174749(v=office.11).aspx) said this is valid and has an example in it. I have tried this in EXCEL VBA and it works.
TypeError: 'unicode' object is not
callable
Any ideas?
Thanks.
Doanld
import win32com.client
xlApp = win32com.client.DispatchEx('Excel.Application')
xlApp.Visible = True
objWkb = xlApp.Workbooks.Add()
objSht = objWkb.Worksheets(1)
objSht.Cells(2,2).Value = '1'
objSht.Cells(2,3).Value = '2'
range = objSht.Cells(2,4)
range.Value = '=%s+%s' % (objSht.Cells(2,2).Address, objSht.Cells(2,3).Address)
range.AddComment('Test Comment')
print range.Address
print range.Address(RowAbsolute=False, ColumnAbsolute=False)
objWkb.Close(SaveChanges=False) #to avoid prompt
xlApp.Quit()
xlApp.Visible = 0 #must make Visible=0 before del self.excelapp or EXCEL.EXE remains in memory.
del xlApp
Range.Address is a parameterized property. It provides a value when accessed like a property, but can be called like a method with parameters as well. PyWin32 does not support parameterized properties directly. It works around this by providing a GetXXXXX method for each property that supports parameters. Use:
range.GetAddress(RowAbsolute=False,ColumnAbsolute=False)
It can be used with or without keywords.
Use either:
range.GetAddress()
range.Address
To read the property.