I need to use zoom in only xlwings, below code is not worked.
Plz help me....
import xlwings as xw
xw.App(visible=True)
workbook = xw.Book(r'zoom.xlsx')
sheet = workbook.sheets.active
# sheet.api.ActiveWindow.Zoom = 100
# sheet.app.api.active_window.zoom.set(100)
# excel.ActiveWindow.Zoom = 80
# sheet.api.PageSetup.Zoom = 100
import xlwings as xw
app = xw.apps.active
app.api.ActiveWindow.DisplayGridlines = False
app.api.ActiveWindow.Zoom = 80
Related
I have this code that basically give me the lat and long when I give it the direction. It is planted to use the API of google but now I need to use the Tomtom API. I donĀ“t know how to do it.
import openpyxl
from openpyxl import load_workbook
import pandas as pd
ds_address=('C:/Users...
wb = load_workbook(filename = ds_address)
data = wb['Sheet1']
#########################
######### 02 - API GOOGLE
#########################
import googlemaps
YOUR_API_KEY =
gmaps = googlemaps.Client(key=YOUR_API_KEY)
def geo_coding_google(adrss):
geocode_result = gmaps.geocode(adrss)
lat,lng = geocode_result[0]['geometry']['location']['lat'],geocode_result[0]['geometry']['location']['lng']
return(lat,lng)
#########################
######### 03 - Build Data
#########################
out = []
for r in range(2,101):#42207):
try:
id=str(data.cell(row=r, column=1).value).lower().encode('utf-8').strip()
adrss=str(data.cell(row=r, column=2).value).lower().encode('utf-8').strip()
adrss=str(adrss)+",medellin,antioquia,colombia"
print(adrss)
g_c=geo_coding_google(str(adrss))
#### Save Data
out.append({'id':id,'direccion':adrss,'lat':g_c[0],'lon':g_c[1]})
except IndexError:
out.append({'id':"NA",'direccion':"NA",'lat':"NA"[0],'lon':"NA"[1]})
pass
#########################
######### 04 - Export data
#########################
df = pd.DataFrame(out)
file_name="C:/Users
Thanks
You need a library that supports TomTom Geocoding endpoint.
For example: https://geocoder.readthedocs.io/providers/TomTom.html
>>> import geocoder
>>> g = geocoder.tomtom(adrss, key='<API KEY>')
>>> result = g.latlng
I have an application from where I grab the image and add the .xls file. I am doing this in a loop so that multiple images will be added. However I found only the last image is added to all locations. I have simplified my code and add here, does the same thing. Here screen grab is used and with the pause function I am changing the screen so the images will be different. It does the same thing, only adds last screenshot to all locations. Please let me know where I am going wrong. Pardon me for code, I am not a programmer.
import openpyxl
import PIL
from PIL import ImageGrab
from openpyxl.drawing.image import Image
def pause():
programPause = input("Press <enter> key")
column_offset=10
row_offset=20
column_start=3
row_start=3
def screen_capture():
img=ImageGrab.grab()
img.save('test.jpg','JPEG')
wb = openpyxl.Workbook()
ws = wb.active
rowi=row_start
for x in range(1,3):
columnj = column_start
for y in range(1,2):
screen_capture()
img1=Image('test.jpg')
img1.anchor = ws.cell(row=rowi, column=columnj).coordinate
ws.add_image(img1)
columnj = columnj+column_offset
pause()
rowi=rowi+row_offset
wb.save('Save_test_data.xlsx')
wb.close()
Following your suggestion I modified the code. It works this way, thank you. Let me know if there is a better way to do
import openpyxl
import PIL
from PIL import ImageGrab
from openpyxl.drawing.image import Image
import os
def pause():
programPause = input("Press <enter> key")
column_offset=10
row_offset=20
column_start=3
row_start=3
def screen_capture(a,b):
img=ImageGrab.grab()
img.save('test'+str(a+b)+'.jpg','JPEG')
wb = openpyxl.Workbook()
ws = wb.active
rowi=row_start
for x in range(1,3):
columnj = column_start
for y in range(1,2):
screen_capture(x,y)
img1=Image('test'+str(x+y)+'.jpg')
img1.anchor = ws.cell(row=rowi, column=columnj).coordinate
ws.add_image(img1)
columnj = columnj+column_offset
pause()
rowi=rowi+row_offset
wb.save('Save_test_data.xlsx')
wb.close()
for x in range(1,3):
for y in range(1,2):
os.remove('test'+str(x+y)+'.jpg')
You have to give each image file a different name.
I'm trying to autofill with "fill series" formatting the value of cell A11 into A12 on two worksheets. This needs to be achieved using win32com module. My code is:
from win32com.client import Dispatch
from win32com.client import constants
xl = Dispatch('Excel.Application')
xl.Visible = True
wb = xl.Workbooks.Open ('S:\\Height Peak.xls')
ws = wb.Worksheets(['Sheet1','Sheet2'])
ws.Select()
ws.Range('A10:A11').AutoFill(ws.Range('A11:A12'), xlFillSeries)
As soon as I run the code, I'm encountering the following error:
AttributeError: unknown.Range
There were 3 Problems:
1) You need to iterate over your worksheets!
2) The source Range
needs to be a subrange of the fill Range. That is not documented well
and I basically just figured that out from looking at examples in the
docs.
3) You import constants, but you need to actually specify your
constants' source! (see below
Code:
from win32com.client import Dispatch
from win32com.client import constants as const
xl = Dispatch('Excel.Application')
xl.Visible = True
wb = xl.Workbooks.Open ('S:\\Height Peak.xls')
ws = wb.Worksheets
for sheet in ws:
if sheet.Name.endswith("1") or sheet.Name.endswith("2"):
sourceRange = sheet.Range('A1:A10')
fillRange = sheet.Range('A1:A12')
sourceRange.AutoFill(fillRange, const.xlFillSeries)
Could anyone please help me in setting a title to a powerpoint slide using win32com library in Python. The following is the code. I have used the slide layout 11 which denotes Title only
import openpyxl as op
import pptx
import os
import win32com.client
import smtplib
os.chdir(r'C:\Users\aju.mathew.thomas\Desktop\PBC\Pepsi\PBC\Performance Reports\2019\PPT')
path= r'C:\Users\aju.mathew.thomas\Desktop\PBC\Pepsi\PBC\Performance Reports\2019\PPT\Summary2.xlsx'
wb = op.load_workbook(path)
ExcelApp = win32com.client.Dispatch("Excel.Application")
ExcelApp.Visible = False
workbook = ExcelApp.Workbooks.open(r'C:\Users\aju.mathew.thomas\Desktop\PBC\Pepsi\PBC\Performance Reports\2019\PPT\Summary2.xlsx')
worksheet = workbook.Worksheets("Summary")
excelrange = worksheet.Range("A2:R24")
PptApp = win32com.client.Dispatch("Powerpoint.Application")
PptApp.Visible = True
z= excelrange.Copy()
PPtPresentation = PptApp.Presentations.Open(r'C:\Users\aju.mathew.thomas\Desktop\PBC\Pepsi\PBC\Performance Reports\2019\PPT\PBC Performance Update.pptx')
pptSlide = PPtPresentation.Slides.Add(1,11)
#pptSlide.Title.Characters.Text ='Metrics'
#title = pptSlide.Shapes.Title
#title.Text ='Metrics Summary'
pptSlide.Shapes.PasteSpecial(z)
PPtPresentation.Save()
Just a small syntax issue:
PptApp = win32com.client.Dispatch("Powerpoint.Application")
PptApp.Visible = True
z= excelrange.Copy()
PPtPresentation = PptApp.Presentations.Open(r'C:\Users\aju.mathew.thomas\Desktop\PBC\Pepsi\PBC\Performance Reports\2019\PPT\PBC Performance Update.pptx')
pptSlide = PPtPresentation.Slides.Add(1,11)
title = pptSlide.Shapes.Title
title.TextFrame.TextRange.Text = 'My title here'
I can't figure this one out. It's complaining about the wb.save() line. I have no idea what's causing it after banging my head on this. I suspect it has something to do with trying to open a blank sheet and saving it after doing stuff with formatting, but I can't imagine what I'm doing there that's causing this problem. It worked fine when I opened an existing spreadsheet and did manipulations, but that required me to have an existing spreadsheet in the first place. Here, I'm trying to start a new spreadsheet from scratch.
from bs4 import BeautifulSoup
from lxml import etree
import os, codecs
import imageFilesSub
import re
import openpyxl, lxml
from openpyxl.utils import get_column_letter, column_index_from_string
homeEnv = 0 # 1 - home, 0 - work
if homeEnv:
filesDir = r'K:\Users\Johnny\My Documents\_World_of_Waterfalls\Website\tier 2 pages\tier 3 pages\tier 4 pages'
filesOutDir = r'K:\Users\Johnny\My Documents\_World_of_Waterfalls\WordPressSite'
else:
filesDir = r'..\old_travelblog_writeups'
filesOutDir = r'./'
# First get the list of files to parse
filesInDir = os.listdir(filesDir)
filesToParse = []
for file in filesInDir:
if ('travel-blog' in file) and (file.endswith('-template.html')):
filesToParse.append(file)
# Open up the travelBlog spreadsheet and set it up
wb = openpyxl.Workbook()
sheet = wb.active
sheet.name = "travelBlog List"
sheet['A1'].value = 'Blog No.'
sheet['B1'].value = 'Title'
sheet['C1'].value = 'Category'
sheet['D1'].value = 'Keyword Tags'
sheet['E1'].value = 'Excerpt'
sheet['F1'].value = 'Featured Image Filename'
sheet['G1'].value = 'Featured Image Alt Text'
sheet['H1'].value = 'Start Date'
sheet['I1'].value = 'End Date'
sheet['J1'].value = 'Old Web Address'
sheet['K1'].value = 'New Travel Blog Body Filename'
sheet['L1'].value = 'Old Travel Blog Template to parse'
sheet.freeze_panes = 'C2'
sheet.column_dimensions['A'].width = 10
sheet.column_dimensions['H','I'] = 20
sheet.column_dimensions['B','F','J','K','L'] = 40
sheet.column_dimensions['D','E'] = 50
from openpyxl.styles import Font
headerFontObj = Font(name='Arial', bold=True)
for col in range(1,sheet.max_column):
sheet.cell(row=1, column=col).font = headerFontObj
wb.save('travelBlogParsed.xlsx')
Thanks in advance,
Johnny
I figured it out. The issue was the following lines:
sheet.column_dimensions['H','I'] = 20
sheet.column_dimensions['B','F','J','K','L'] = 40
sheet.column_dimensions['D','E'] = 50
First of all, apparently, you can't use the column_dimensions method on a vector. The argument must be a string. Second, these lines were missing the .width attribute. So those lines should have been:
sheet.column_dimensions['H'].width = 20
sheet.column_dimensions['I'].width = 20
sheet.column_dimensions['B'].width = 40
...
sheet.column_dimensions['E'].width = 50