Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need Help With a Script
#1
Hi,

I'm still working on trying to get a script together for importing data to my cutter reports. Seems like I've had this script a million different ways... I decided to parse the .csv file manually since the date and time gets exported together from the cutters. I've been opening the .csv file from Excel and modifying the date and time with the separator line to indicate between the two.

Here is how far I've gotten and information about the script.

Source is ImportFile.xlsx that contains all the data from the cutters that I need to move to the destination file. This file has other columns that I do not need to copy over. These rows of data will contain cut data for dates Monday through Friday. This file only has one tab.

Destination is Weekly-temp.xlsx that contains a blank form that the data needs to be imported in by corresponding columns. Tab used to import is the first tab and the title is 'Cutter A - Marker Report'. Columns that need to match from ImportFile to Weekly-temp are (Cutfile Name, Start Time, End Time, Total Time, Cut, Dry Haul, Sharpen, Bite, Interrupt, Processing, Idle, and Dry Run) and the data will start on row 8. Columns go straight across in order of above but skips column G, H, and I. I'm thinking data needs to be pulled by the date on the Weekly-temp and match up with the ImportFile. On the Weekly-temp, it has 5 sections each one with the day of the week and the date at the top of each section. Weekly-temp has 50 rows and normally this is all I need per day.

Here is the script I have so far... I can get the importfile data copied over to the weekly-temp but it is pulling all information over and some are in the wrong columns. Any help would be greatly appreciated and if there is a different way I should be doing this, please advise.

# Importing openpyxl module
import openpyxl as xl;

# Opening the source excel file
filename = "ImportFile.xlsx"
wb1 = xl.load_workbook(filename)
ws1 = wb1.worksheets[0]

# Opening the destination excel file
filename1 = "Weekly-temp.xlsx"
wb2 = xl.load_workbook(filename1)
ws2 = wb2.active

# Calculate total number of rows and columns in 
# source excel file
mr = ws1.max_row
mc = ws1.max_column

# Copying the cell values from source excel file
# destination excel file
for i in range (1, mc + 1):
    for j in range (1, mc + 1):
        # reading cell value from source excel file
        c = ws1.cell(row = i, column = j)
        
        # writing the read value to destination excel file
        ws2.cell(row = i, column = j).value = c.value

# Saving the destination excel file
wb2.save(str(filename1))
Thanks,
Veronica
Larz60+ write Jan-05-2021, 05:07 PM:
Please add post each time you have a change, rather than edit original post.
It's important, for diagnosis, to be able to see code as it develops.
Reply


Messages In This Thread
Need Help With a Script - by SunWers - Jan-05-2021, 05:42 PM
RE: Need Help With a Script - by SunWers - Jan-05-2021, 05:49 PM
RE: Need Help With a Script - by buran - Jan-05-2021, 06:34 PM
RE: Need Help With a Script - by SunWers - Jan-05-2021, 08:56 PM
RE: Need Help With a Script - by buran - Jan-05-2021, 09:00 PM
RE: Need Help With a Script - by SunWers - Jan-05-2021, 09:43 PM
RE: Need Help With a Script - by SunWers - Jan-07-2021, 03:26 AM

Forum Jump:

User Panel Messages

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