Python Forum
Password protected xls data transfer to master
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Password protected xls data transfer to master
#1
Hi,

I am quite new to python and currently writing a code to speed up a VBA process which takes 5 to 6 hours to complete and want to speed it up. The code needs to open a password protected excel, extract certain sheet and cell data to a master sheet and if column A is that same number then override so no duplicates:

Process:

Step 1: Open password protected xls

step 2: check for the duplicated number in column A and if the same value exists then override, copy required cells from each sheet to master wb and data sheet as shown below

step 3: go back to step one until all xls are done.

This is part of the VBA to show the process to a degree:

wbThis.Worksheets("Data").Range("A" & Store_Row_no) = NewNumber

wbThis.Worksheets("Data").Range("B" & Store_Row_no) = DateNew

wbThis.Worksheets("Data").Range("C" & Store_Row_no) = wbNew.Worksheets("Sheet1").Range("F2").Value

wbThis.Worksheets("Data").Range("D" & Store_Row_no) = wbNew.Worksheets("Sheet2").Range("H152").Value

wbThis.Worksheets("Data").Range("E" & Store_Row_no) = wbNew.Worksheets("Sheet3").Range("D3").Value

and this is my current code but can't work out how I open a password protected excel and copy to master sheet and then overide for data column A if it is a duplicate.

Python code so far:

import xlrd

wb = xlrd.open_workbook('C:/Users/')

sh1 = wb.sheet_by_name('Sheet1') #sheet name1

sh2 = wb.sheet_by_name('Sheet3') #sheet name2

sh3 = wb.sheet_by_name('Sheet4') #sheet name3

out1 = sh1.cell(1,1).value # sh.cell(row,column).value

out2 = sh1.cell(1,3).value

out3 = sh1.cell(1,5).value

out4 = sh2.cell(151,7).value

out5 = sh3.cell(2,2).value

print(out1,out2,out3,out4,out5)
Any help would be greatly appreciated, I know this is probably quite simple and I am trying my best to learn via google, youtube and online tutorials but nothing I have seen explains what I want.

UPDATE:

updated the code so can open encrypted excels:

import win32com.client

import sys

password = ' '

xlApp = win32com.client.Dispatch("Excel.Application")

filename = ('C.xls')

wb = xlApp.Workbooks.Open(filename, False, True, None, password)

sh1 = wb.Sheets('sheet1') #sheet name1

sh2 = wb.Sheets('sheet2) #sheet name2

sh3 = wb.Sheets('sheet3') #sheet name2

out1 = sh1.Range("B2").value

out2 = sh1.Range("D2").value

out3 = sh1.Range("F2").value

out4 = sh2.Range("H152").value

out5 = sh3.Range("D3").value

print(out1,out2,out3,out4,out5)
Just need to loop through help and copy to new master wb

Thank you so much in advance
Reply


Messages In This Thread
Password protected xls data transfer to master - by OTH - Feb-15-2021, 12:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Setup host for consistent data transfer to client via TCP Gustav97 0 723 Jun-27-2022, 07:33 PM
Last Post: Gustav97
  Python code to read second line from CSV files and create a master CSV file sh1704 1 2,441 Feb-13-2022, 07:13 PM
Last Post: menator01
Information Estimating transfer function from frd data ymohammadi 0 1,473 Feb-10-2022, 10:00 AM
Last Post: ymohammadi
  Reading a copy-protected PDF CaptainCsaba 6 6,286 Oct-25-2021, 07:06 AM
Last Post: Caslenty
  Login through a protected directory ebolisa 3 2,104 Jul-24-2021, 09:12 PM
Last Post: ebolisa
  Copy data from different workbooks into Master sheet with Python Fatman003 0 2,254 Aug-27-2019, 07:36 AM
Last Post: Fatman003
  Python code to copy data from multiple workbooks into master sheet Fatman003 2 3,848 Aug-21-2019, 11:23 AM
Last Post: Fatman003
  pyserial-master installed bbut not recognized elwolv1 0 2,010 Jan-04-2019, 08:37 PM
Last Post: elwolv1
  Reading data from password protected excel Anirudh_Avantsa 2 22,364 Apr-04-2018, 03:26 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020