脚本分两个文件:

1.生成二维随机列表:GenerateLocaltion.py  2.将列表导入excel文件:CreateExcel.py

先上GenerateLocaltion.py:

import random
class Table(): localtion = [([1] * 9) for i in range(5)]
room = []
def inIt(self):
localtion = [([1] * 9) for i in range(5)]
for i in range(5):
localtion[i][0] = 0
#标志特殊位置
localtion[0][0] = 1
localtion[1][0] = 1
localtion[0][8] = 0
localtion[1][5] = 0
localtion[3] = [0] * 9
localtion[3][1] = 1
localtion[3][2] = 1
localtion[4][4] = 0
localtion[4][5] = 0
localtion[4] = [0] * 9
for i in range(5):
localtion[4][i] = 1 self.localtion = localtion
#生成随机列表
def generateRandomList(self):
#去掉空位
nothing = []
nothing.append(1)
nothing.append(13)
nothing.append(32)
nothing.append(31)
nothing.append(30)
nothing.append(29)
nothing.append(28)
nothing.append(27)
nothing.append(35)
nothing.append(36)
nothing.append(37)
nothing.append(38)
nothing.append(44) self.room = []
i = 0
while len(self.room) < 31:
m = int(random.random()*100 % 44 + 1)
if m not in self.room and m not in nothing:
self.room.append(m)
i += 1
return self.room
def generateLocal(self):
#随机列表对座位赋值
for i in range(5):
for j in range(9):
if self.localtion[i][j] == 1:
self.localtion[i][j] = self.room.pop(0)
return self.localtion
def getTable(self):
self.inIt()
self.generateRandomList() return self.generateLocal()

  代码很长,主要因为要特殊照顾一些位置,思路就是生成一个足够个数的随机序列(不能重复,不能有对应空位的座位号)往二维列表里塞,其他的都很简单

CreateExcel.py:

用xlwt模块和easygui模块

xlwt中调用的函数:

sheet.write_merge()函数:参数1,2,3,4可以理解为用行和列描述一块区域,前两个为行,后两个为列例如,i,i+n,j,j+n,边长为n的正方形

sheet.write()函数:向单元格中填充内容,参数1,2表示单元格坐标,参数3表示填充的内容,参数4是单元格格式

'''
Created on 2017年7月21日 @author: Garbos
'''
#coding:utf-8
import xlwt
import easygui as g
from GenerateLocaltion import Table as table
def setUnitStyle(name,height,bold=False):
style = xlwt.XFStyle() font = xlwt.Font()
font.name = name
font.bold = bold
font.color_index = 4
font.height = height
style.font = font return style def createExcel():
#創建工作簿
e = xlwt.Workbook() #創建表格sheet1
sheet1 = e.add_sheet(u'sheet1',cell_overwrite_ok=True) #創建第一行
sheet1.write_merge(0,0,0,3,u'',setUnitStyle('Times New Roman',500,False))
sheet1.write_merge(0,0,3,10,u'ACM 404集训座位表',setUnitStyle('Times New Roman',500,False))
sheet1.write_merge(1,1,1,4,u'',setUnitStyle('Times New Roman',300,False))
sheet1.write_merge(1,1,6,10,u'',setUnitStyle('Times New Roman',300,False))
sheet1.write(1,5,u'讲台',setUnitStyle(u'微软雅黑',400,True))
sheet1.write_merge(3,5,5,6,u'走廊',setUnitStyle('Times New Roman',800,False))
sheet1.write_merge(2,2,5,6,u'',setUnitStyle('Times New Roman',300,False))
sheet1.write_merge(6,6,5,6,u'',setUnitStyle('Times New Roman',300,False))
sheet1.write(1,0,u'门',setUnitStyle(u'微软雅黑',400,False))
gt = table()
t = gt.getTable() for i in range(5):
for j in range(9):
if t[i][j] == 0:
continue
temp = j
if temp >= 5:
temp += 2
sheet1.write(i+2,temp,t[i][j],setUnitStyle(u'微软雅黑',250,False))
filename = '404座位表.xls'
e.save(filename)#坑,xlsx无法打开 remind = g.msgbox(msg = filename + ' 已生成!',title='404座位表生成器',
ok_button = '取消')
if __name__ =='__main__':
createExcel()

 最后用Pyinstaller打包

        

python生成excel格式座位表的更多相关文章

  1. 小兴趣:用python生成excel格式座位表

    脚本分两个文件: 1.生成二维随机列表:GenerateLocaltion.py 2.将列表导入excel文件:CreateExcel.py 先上GenerateLocaltion.py: impor ...

  2. Python生成文本格式的excel\xlwt生成文本格式的excel\Python设置excel单元格格式为文本\Python excel xlwt 文本格式

    Python生成文本格式的excel\xlwt生成文本格式的excel\Python设置excel单元格格式为文本\Python excel xlwt 文本格式 解决: xlwt 中设置单元格样式主要 ...

  3. Html Table用JS导出excel格式问题 导出EXCEL后单元格里的000412341234会变成412341234 7-14 会变成 2018-7-14(7月14) 自定义格式 web利用table表格生成excel格式问题 js导出excel增加表头、mso-number-format定义数据格式 数字输出格式转换 mso-number-format:"\@"

    Html Table用JS导出excel格式问题 我在网上找的JS把HTML Tabel导出成EXCEL.但是如果Table里的数字内容为0开的的导成Excel后会自动删除0,我想以text的格式写入 ...

  4. python生成Excel图表(通过xlsxwriter)

    前面介绍了pandas的简单用法,pandas的数据可以通过matlab第三方包将数据生成报表,但是我想将报表生成在Excel中,这时候就可以借助xlsxwriter第三方包来生成图标   缺点:xl ...

  5. python 生成json格式文件,并存储到手机上

    上代码 #!/usr/bin/env python # -*- encoding: utf-8 -*- import json import os import random "" ...

  6. python生成excel测试数据

    在功能测试时,经常会测到excel文件导入导出的功能,导入与导出时,需要测试系统单次导入大批量数据时是否正常, 如果系统承受不起太大的数据导入,则需要开发限制单次导入的数量,以防止系统服务异常.大量的 ...

  7. web利用table表格生成excel格式问题

    当我们把web页面上的table导成excel形式时,有时候我们的数据需要以特定的格式呈现出来,这时候我们就需要给指定的单元格添加一些样式规格信息. 文本:vnd.ms-excel.numberfor ...

  8. (一)python 格式化 excel 格式

    需求: 客户通过 sftp 上传了一个 poc测试的 excel文件, 下到 云桌面 查看,发现一堆格式问题, 怎么办呢? 公司又不允许 吧文件下载到本地处理, 只能在 服务器上进行处理. 一堆的类型 ...

  9. python 生成excel,并下载到本地

    from django.shortcuts import reverse,redirect,render from operations import models import xlwt impor ...

随机推荐

  1. GreenDao学习

    官方文档地址:http://greenrobot.org/greendao/documentation//introduction/ 英语不好的可以使用谷歌翻译,很轻松的看懂文档,不需要FQ. 看不懂 ...

  2. python 学习2 测试报告

    1. py.test test_class.py  --resultlog=./log.txt 2.生成html格式 py.test test_class.py --html=./report.htm ...

  3. jQuery效果之显示与隐藏

    .hide([duration][,complete])--目标元素的隐藏. .show([duration][,complete])--目标元素的显示: .toggle([duration][,co ...

  4. cocos2d-x 2.x 支持多个方向屏幕翻转

    主要改动 RootViewController.mm 的 supportedInterfaceOrientations 方法 1.四个方向 UIInterfaceOrientationMaskAll ...

  5. Linux 安装OpenSSL出错的解决方法

    以前编译php没有 –with–openssl 现在要使用到 openssl ,phpinze扩展安装,但是在make时候报错 今天找这个在网上找了大半天,最后总结应该是php版本本身的问题,错误是p ...

  6. 笔试真题解析 ALBB-2015 算法project师实习生机试

    1.用十进制计算30!(30的阶乘),将结果转换成3进制进行表示的话,该进制下的结果末尾会有____个0. [解析] 计算N.下3进制结果末尾有多少个0,事实上就是计算3进制中的3被进位多少次,仅仅要 ...

  7. Windows环境下搭建SVN服务器

    使用 VisualSVN Server来实现主要的 SVN功能则要比使用原始的 SVN和Apache相配合来实现源代码的 SVN管理简单的多,下面就看看详细的说明. VisualSVN Server的 ...

  8. 更改eclipse(myeclipse) author的默认名字(注释的作者)

    在eclipse/myeclipse中,当添加注释的作者选项时,@author 后边一般都会默认填充的你登录计算机的用户名.如何去修改呢:第一种方法:修改计算机登录的用户名(一般不实用)第二种方法:修 ...

  9. Effective Java 读书笔记(一):使用静态工厂方法代替构造器

    这是Effective Java第2章提出的第一条建议: 考虑用静态工厂方法代替构造器 此处的静态工厂方法并不是设计模式,主要指static修饰的静态方法,关于static的说明可以参考之前的博文&l ...

  10. Asp.Net网站统一处理错误信息

    1.创建Global.asax文件 2.在Application_Error里统一处理,可以写入文件,也可以写入SQL.代码如下 Exception ex = Server.GetLastError( ...