Python Forum
Program writing excel rfile with randomnized input
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Program writing excel rfile with randomnized input
#1
Hello everyone.

I'm new to python. I have already tried to make some smal programs as excercise and that works fine for me but now i wanted to make something useful for me.

I have different excel files (list with, names, forname, adress, phone number...). Each excel file has its own list. 

Now i want to make a program that can:
  1. make one fictive person out of the different excel files (i think mine works!)
  2. write this to a new excel file
  3. Asking the user to give how many fictive persons he wants to make and write them all to one excel file. 
I a later stage i would like to expend this to be able to choose wether i want male/female/ which province they live... . 

This is what i have for now:

import xlrd
import random
import xlsxwriter

#==> This I did for every workbook.
workbook = xlrd.open_workbook("achternamen.xlsx")

worksheet = workbook.sheet_by_index(0)

total_rows = worksheet.nrows

total_cols = worksheet.ncols

tableAchternamen = list()
recordAchternamen = list()

for x in range(total_rows):
   for y in range(total_cols):
       recordAchternamen.append(worksheet.cell(x,y).value)
   tableAchternamen.append(recordAchternamen)
   recordAchternamen = []
   x +=1

#==> This give me a result printed on Python
SlachtofferAchternaam = print(random.choice(tableAchternamen))
SlachtofferVoornamen = print(random.choice(tableVoornamen))
SlachtofferTelefoonnummer = print(random.choice(tableTelefoonnummers))
SlachtofferAdressen = print(random.choice(tableAdressen))


resultaat = (
['Achternaam', SlachtofferAchternaam],
['Voornaam', SlachtofferVoornamen],
['Telefoonnummer', SlachtofferTelefoonnummer],
['Adres',SlachtofferAdressen],
)

#Start van de cellen die gebruikt worden
row = 0
col = 0

for item, cost in (resultaat):
   worksheet.write(row, col, item)
   worksheet.write(row, col + 1, cost)
   row += 1

workbook.close()
Please any help is welcome! ! ! 
Reply
#2
I'm not sure what the issue is, but I don't think your results have any values at all. print() doesn't return a value, so SlachtofferAchternaam = print(random.choice(tableAchternamen)) would mean SlachtofferAchternaam would always == None. Which is probably not what you want.

Also, you don't really need x += 1. The for loop will do that for you :p
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] Results of this program in an excel file eisamabodian 1 1,574 Feb-11-2022, 03:18 PM
Last Post: snippsat
  Need Help writing data into Excel format ajitnayak87 8 2,503 Feb-04-2022, 03:00 AM
Last Post: Jeff_t
  Writing on an lcd display gives problems to the program Idontknowany 1 1,401 Nov-15-2021, 10:46 PM
Last Post: Larz60+
  I am writing a car rental program on python. In this function I am trying to modify aboo 2 2,730 Aug-05-2021, 06:00 PM
Last Post: deanhystad
Smile Set 'Time' format cell when writing data to excel and not 'custom' limors 3 6,279 Mar-29-2021, 09:36 PM
Last Post: Larz60+
  Writing to existing excel sheet jksvend 0 1,938 Oct-12-2020, 11:19 AM
Last Post: jksvend
  How can I speed up my openpyxl program reading Excel .xlsx files? deac33 0 3,392 May-04-2020, 08:02 PM
Last Post: deac33
  Keyboard Module Python - Suppress input while writing to window ppel123 0 2,788 Apr-08-2020, 02:51 PM
Last Post: ppel123
  Python program for excel tummpy06 2 1,696 Dec-18-2019, 12:21 PM
Last Post: jefsummers
  How to write a script to execute a program need passing additional input? larkypython 2 2,520 Nov-23-2019, 04:38 AM
Last Post: larkypython

Forum Jump:

User Panel Messages

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