win32com

Should I use pyodbc or win32com to fill out pre-existing forms in a Microsoft Access Database (.accdb) using python?

匆匆过客 提交于 2020-07-09 12:48:50
问题 I wrote a python script that extracts strings from word documents. The goal is to then insert these strings into a pre-existing form in an Access database, save it, create a duplicate of the form, insert different strings from the next word document, save, repeat. The form already has all the fields I need, and it has buttons for 'save' and 'create duplicate.' I'm having trouble figuring out how to insert strings into the Access form. So far I've learned that there are at least two ways of

Using Python win32com to get list of Excel worksheets

末鹿安然 提交于 2020-06-29 03:42:23
问题 Looking for a simple way to get a list of the worksheets in an Excel workbook using win32com in Python 3. I would prefer to avoid iterating, but can't find a function to do so. 回答1: Callig the .Sheets property of the workbook, returns a Sheets collection, <win32com.gen_py.Microsoft Excel 16.0 Object Library.Sheets instance at 0x1597583762504> In order to get each sheet, you must iterate , which returns an object, <win32com.gen_py.Microsoft Excel 16.0 Object Library._Worksheet instance at

How to create a pivot table in Excel with python win32com

喜你入骨 提交于 2020-06-27 04:10:06
问题 Given an existing Excel file, with data in a long format Automate creating the following pivot table in Excel with the Python win32com module Following is code to setup test.xlsx with data and connect to create a Excel com object Imports import win32com.client as win32 from pathlib import Path import sys import pandas as pd import numpy as np import random from datetime import datetime win32c = win32.constants Function to create test.xlsx This function is only to provide test data and a file

Trouble loading Bloomberg addins on excel using python

纵饮孤独 提交于 2020-06-17 15:47:08
问题 I am trying to open an excel which is connected to BBG and refresh values. To open an instance of excel and load bloomberg addins, I used a solution from the attached link a while ago Python using win32com wont update excel sheet with needed Add-ins The solution worked fine for me till yday when for some reason xlapp.RegisterXLL('C:/blp/API/Office Tools/bofaddin.dll') is giving me trouble. i.e. not loading and crashing my codes. Anyone has any ideas whats happening? Codes are below if anyone

Python code to refresh the connection in individual excel sheet

假装没事ソ 提交于 2020-06-17 14:37:12
问题 I am a beginner in python. I have written few DBQ statements in excel to fetch result in excel which should be refreshed whenever the excel is opened. Have given the correct setting in connection properties. Below is my python code for refreshall:- import win32com.client import time xl = win32com.client.DispatchEx("Excel.Application") wb = xl.workbooks.open("D:\\Excel sheets\\Test_consolidation.xlsx") xl.Visible = True time.sleep(10) wb.Refreshall() I have 3 sheets in the excel file, which

how to list all Excel Macro Names using Python

杀马特。学长 韩版系。学妹 提交于 2020-05-19 02:31:52
问题 I am developing this app that loads an excel sheet and allows users to run macros and tag cells. I ran in to a problem trying to read Macros from the Excel sheet. I am using win32com module for all the excel access. So far it has been good to me. But am struggling trying to create code that will provide me with all the macros. I have the corresponding VBA code that does provide with me the macros but I have so far been unsuccessful trying to translate it in to python. I want to read all the

how to list all Excel Macro Names using Python

好久不见. 提交于 2020-05-19 02:31:11
问题 I am developing this app that loads an excel sheet and allows users to run macros and tag cells. I ran in to a problem trying to read Macros from the Excel sheet. I am using win32com module for all the excel access. So far it has been good to me. But am struggling trying to create code that will provide me with all the macros. I have the corresponding VBA code that does provide with me the macros but I have so far been unsuccessful trying to translate it in to python. I want to read all the

Can we copy a dataframe, with rows and cols >1, into an excel sheet?

纵饮孤独 提交于 2020-05-17 14:46:11
问题 Here's the code I am using excel = win32com.client.Dispatch('Excel.Application') wb = excel.Workbooks.Open('myWorkbook.xlsx') df = pd.DataFrame({'A':[1,2,3,4,5], 'B':[11,22,33,44,55], 'C':['a','b','c','d','e']}) wb.Sheets('Template').Copy(Before=None, After=wb.Sheets(wb.Sheets.count)) ws = wb.Sheets(wb.Sheets.count) ws.Range(ws.cells(40,19), 40+len(df.index)-1, 19+len(df.columns)).Value = df.values But I always receive the following error: ValueError: ndarray is not C-contiguous 来源: https:/

Can we copy a dataframe, with rows and cols >1, into an excel sheet?

可紊 提交于 2020-05-17 14:42:01
问题 Here's the code I am using excel = win32com.client.Dispatch('Excel.Application') wb = excel.Workbooks.Open('myWorkbook.xlsx') df = pd.DataFrame({'A':[1,2,3,4,5], 'B':[11,22,33,44,55], 'C':['a','b','c','d','e']}) wb.Sheets('Template').Copy(Before=None, After=wb.Sheets(wb.Sheets.count)) ws = wb.Sheets(wb.Sheets.count) ws.Range(ws.cells(40,19), 40+len(df.index)-1, 19+len(df.columns)).Value = df.values But I always receive the following error: ValueError: ndarray is not C-contiguous 来源: https:/

How to check if a large Excel file is protected as quickly as possible?

懵懂的女人 提交于 2020-02-29 09:10:31
问题 How to check if excel file is protected with password the fastest way (without trying to open it and placing an exception)? Updated: from zipfile import * from openpyxl import load_workbook filename = 'Z:\\path_to_file\\qwerty.xlsm' # protected one try: wb = load_workbook(filename, data_only=True, read_only=True) except (BadZipfile) as error: print(is_zipfile(filename)) A problem is that I got False as an output, thus I cannot get rid of the exception and replace it with is_zipfile()