当前位置:首页 » 编程语言 » pythonstyle

pythonstyle

发布时间: 2023-05-17 20:28:21

‘壹’ python xlwt怎么给单元格中部分字设置颜色

#coding=utf-8

import xlwt

#file = xlwt.Workbook(encoding = 'utf-8')

wbk = xlwt.Workbook(encoding = 'utf-8')

sheet = wbk.add_sheet('sheet 1', cell_overwrite_ok=True)

#这样表单就被创建了,写入数据也很简单:

# indexing is zero based, row then column

#sheet2 = wbk.add_sheet('sheet 2', cell_overwrite_ok=True)

style = xlwt.XFStyle()

font = xlwt.Font()

font.name = 'SimSun' # 指定“宋体”

style.font = font

sheet.write(0,1,'test text')

#sheet.write(1,2,'excel读写测试',style)

sheet.write(1,2,'excel读写测试',xlwt.easyxf('font: height 240, name Arial, colour_index black, bold off, italic on; align: wrap on, vert centre, horiz left;')

)

#之后,就可以保存文件(这里不需要想打开文件一样需要close文件):

wbk.save('test4.xls')
请看代码示例二:
## Startup Code Begin
import xlwt
from xlwt import *
import string
import os
from datetime import datetime
import time
from time import gmtime, strftime
current_date = strftime("%b %d %Y (%H:%M)")
## Startup Code End

## Moles Begin
def _size_col(sheet, col):
return sheet.col_width(col)

def _size_row(sheet, row):
return sheet.row_height(row)
## Moles End

## Style variable Begin
tittle_style = xlwt.easyxf('font: height 400, name Arial Black, colour_index blue, bold on; align: wrap on, vert centre, horiz center;' "borders: top double, bottom double, left double, right double;")
subtittle_left_style = xlwt.easyxf('font: height 240, name Arial, colour_index brown, bold on, italic on; align: wrap on, vert centre, horiz left;' "borders: top double, bottom double, left double;")
subtittle_right_style = xlwt.easyxf('font: height 240, name Arial, colour_index brown, bold on, italic on; align: wrap on, vert centre, horiz left;' "borders: top double, bottom double, right double;")
subtittle_top_and_bottom_style = xlwt.easyxf('font: height 240, name Arial, colour_index black, bold off, italic on; align: wrap on, vert centre, horiz left;' "borders: top double, bottom double;")
blank_style = xlwt.easyxf('font: height 650, name Arial, colour_index brown, bold off; align: wrap on, vert centre, horiz left;' "borders: top double, bottom double, left double, right double;")
normal_style = xlwt.easyxf('font: height 240, name Arial, colour_index black, bold off; align: wrap on, vert centre, horiz left;' "borders: top double, bottom double, left double, right double;")
## Style variable End

## Mole Add Begin
def print_blank_line(A, B, C, D):
ws.write_merge(A, B, C, D, "", xlwt.easyxf('font: height 240, name Arial, colour_index black, bold off, italic on; align: wrap on, vert centre, horiz left;'))
## Mole Add End

## Variable Begin
Excel = xlwt.Workbook()
## Variable End

## Sheet Name Begin
ws = Excel.add_sheet('Test Sheet')
## Sheet Name End

## Column Width Determine Begin
for A in range(100):
ws.col(A).width = 600
## Column Width Determine Begin

## Tittle Picture Begin
ws.write_merge(0, 0, 0, 42, "", xlwt.easyxf('font: height 700, name Arial, colour_index brown, bold off; align: wrap on, vert centre, horiz left;'))
##ws.insert_bitmap('test.bmp', 0, 0, 60, 5, 1.75, 1)
## Tittle Picture End

## Subtittle Write Begin
# Variable Begin
job_name = "Nicolas_Parametric"
fab_name = "Nicolas_Parametric"
printed_by = "Nic"
printed_date = current_date
# Variable End

border_type = ["dashed", "double", ""]

ws.write_merge(1, 1, 0, 6, "Job Name:", xlwt.easyxf('font: height 240, name Arial, colour_index black, bold on, italic on; align: wrap on, vert centre, horiz left;' "borders: top double, bottom double, left double;"))
ws.write_merge(1, 1, 7, 21, job_name, xlwt.easyxf('font: height 240, name Arial, colour_index black, bold off, italic on; align: wrap on, vert centre, horiz left;' "borders: top double, bottom double;"))
ws.write_merge(2, 2, 0, 6, "Fab Name:", xlwt.easyxf('font: height 240, name Arial, colour_index black, bold on, italic on; align: wrap on, vert centre, horiz left;' "borders: top double, bottom double, left double;"))
ws.write_merge(2, 2, 7, 21, fab_name, xlwt.easyxf('font: height 240, name Arial, colour_index black, bold off, italic on; align: wrap on, vert centre, horiz left;' "borders: top double, bottom double;"))

ws.write_merge(1, 1, 22, 27, "Printed By:", xlwt.easyxf('font: height 240, name Arial, colour_index black, bold on, italic on; align: wrap on, vert centre, horiz left;' "borders: top double, bottom double;"))
ws.write_merge(1, 1, 28, 42, printed_by, xlwt.easyxf('font: height 240, name Arial, colour_index black, bold off, italic on; align: wrap on, vert centre, horiz left;' "borders: top double, bottom double, right double;"))
ws.write_merge(2, 2, 22, 27, "Printed Date:", xlwt.easyxf('font: height 240, name Arial, colour_index black, bold on, italic on; align: wrap on, vert centre, horiz left;' "borders: top double, bottom double;"))
ws.write_merge(2, 2, 28, 42, printed_date, xlwt.easyxf('font: height 240, name Arial, colour_index black, bold off, italic on; align: wrap on, vert centre, horiz left;' "borders: top double, bottom double, right double;"))

print_blank_line(3, 3, 0, 42)
ws.write_merge(4, 4, 0, 42, "Report Name", xlwt.easyxf('font: height 400, name Arial, colour_index red, bold on, italic on, underline on; align: wrap on, vert centre, horiz center;'))
print_blank_line(5, 5, 0, 42)

ws.write_merge(6, 6, 0, 1, "#", xlwt.easyxf('font: height 240, name Arial, colour_index black, bold on, italic on; align: wrap on, vert centre, horiz left;' "borders: top double, bottom double, left double, right double;"))
ws.write_merge(6, 6, 2, 7, "Piecemark", xlwt.easyxf('font: height 240, name Arial, colour_index black, bold on, italic on; align: wrap on, vert centre, horiz left;' "borders: top double, bottom double, left dashed, right double;"))
ws.write_merge(6, 6, 8, 10, "Qty", xlwt.easyxf('font: height 240, name Arial, colour_index black, bold on, italic on; align: wrap on, vert centre, horiz left;' "borders: top double, bottom double, left dashed, right double;"))
ws.write_merge(6, 6, 11, 20, "Size", xlwt.easyxf('font: height 240, name Arial, colour_index black, bold on, italic on; align: wrap on, vert centre, horiz left;' "borders: top double, bottom double, left dashed, right double;"))
ws.write_merge(6, 6, 21, 34, "Status", xlwt.easyxf('font: height 240, name Arial, colour_index black, bold on, italic on; align: wrap on, vert centre, horiz left;' "borders: top double, bottom double, left dashed, right double;"))
ws.write_merge(6, 6, 35, 42, "Date", xlwt.easyxf('font: height 240, name Arial, colour_index black, bold on, italic on; align: wrap on, vert centre, horiz left;' "borders: top double, bottom double, left dashed, right double;"))
## Subtittle Write End

normal_font = xlwt.easyxf('font: height 240, name Arial, colour_index black; align: wrap on, vert centre, horiz left;' "borders: top dashed, bottom dashed, left double, right double;")

for A in range(98):
ws.write_merge(7 + A, 7 + A, 0, 1, "", normal_font)
ws.write_merge(7 + A, 7 + A, 2, 7, "", normal_font)
ws.write_merge(7 + A, 7 + A, 8, 10, "", normal_font)
ws.write_merge(7 + A, 7 + A, 11, 20, "", normal_font)
ws.write_merge(7 + A, 7 + A, 21, 34, "", normal_font)
ws.write_merge(7 + A, 7 + A, 35, 42, "", normal_font)

## File Save As Begin
Excel.save('Test.xls')
## File Save As End

#### Start File Begin
##os.startfile("C:/Documents and Settings/dev01/Desktop/Test.xls")
#### Start File End

‘贰’ python-docx怎么给表格自定义样式

1、word表格样式的设置
from docx import *
document = Document()
table = document.add_table(3, 3, style="Medium Grid 1 Accent 1")
heading_cells = table.rows[0].cells
heading_cells[0].text = '第一列内容'
heading_cells[1].text = '第二列内容'
heading_cells[2].text = '第三列内容'
document.save(r"d:\demo.docx")

2、获取所有word表格样敬拿陆式
from docx.enum.style import WD_STYLE_TYPE
from docx import *
document = Document()
styles = document.styles

#生成亮顷所有表样式
for s in styles:
if s.type == WD_STYLE_TYPE.TABLE:
document.add_paragraph("表格样式 : "+ s.name)
table = document.add_table(3,3, style = s)
heading_cells = table.rows[0].cells
heading_cells[0].text = '第一列内容'
heading_cells[1].text = '第二列内容'
heading_cells[2].text = '第三列内容'敏薯
document.add_paragraph("\n")

‘叁’ selenium3+python可以更改元素的style吗

要点击一个 Menu 时需要对 SPAN 元素进行操作,后来喊启侍在 Selenium 的论坛中找郑吵到了答案。示例代码如下:
1

2 click
3 //span[contains(text(),'String')]
4
5
在实际使用时,把 String 部分替换为实际的 text 就可以了。
另外一旁汪种做法是不行的:

1
2 click
3 //span[@text='String']
4
5

‘肆’ Python 插曲:编码风格是如何使用的呢

插曲:编码风格
此时你已经可以写一些更长更复杂的 Python 程序,是时候讨论一下 编码风格 了。大多数语言可以写(或者更明白的说, 格式化 )作几种不同的风格。有些比其它的更好读。让你的代码对别人更易读是个好想法,养成良好的编码风格对此很有帮助。
对于 Python,PEP 8 引入了大多数项目遵循的风格指导。它给出了一个高度可读,视觉友好的编码风格。每个 Python 开发者都应该读一下,大多数要点都会对你有帮助:
使用 4 空格缩进,而非 TAB
在小缩进(可以嵌套更深)和大缩进(更易读)之间,4空格是一个很好的折中。TAB 引发了一些混乱,最好弃用
折行以确保其不会超过 79 个字符
这有助于小显示器用户阅读,也可以让大显示器能并排显示几个代码文件
使用空行分隔函数和类,以及函数中的大块代码
可能的话,注释独占一行
使用文档字符串
把空格放到操作符两边,以及逗号后面,但是括号里侧不加空格:a = f(1, 2) + g(3, 4)
统一函数和类命名
推荐类名用 驼峰命名, 函数和方法名用 小写_和_下划搭清键线。总是用 self 作为方法的第一个参数(关于类和方法的知识详见 初识类 )
不要使用花哨的编码,如果你的代码的目的是要在国际化环境。Python 的默认情况下,UTF-8,甚至普通的 ASCII 总是知巧工作的最好
同样,也不正则要使用非 ASCII 字符的标识符,除非是不同语种的会阅读或者维护代码。

‘伍’ Python命名规则与注释风格

名称不要缩写!!!

名称不要缩写!!!

名称不要缩写!!!

包命名:小写,下划线_连接单词

模块命名:小写,下划线_连接单词

类命名:双驼峰,MyClass

函数命名:小写,下划线_连接单词

全局变量:每个字母大写

注释很重要,要注明函数或类的功能,参数的数据类型、含义等。

注释模板:

注释的作用:

Python有句话是do not repeat yourself,即不要做重复的事,因此出现了类或函数的封装和继承,基于此可提高代码的重复利用性。

‘陆’ python语言属于什么语言

Python是一种跨平台的计算机程序设计语言。是一种面向对象的动态类型语言,最初被设计用于编写自动化脚本(shell),随着版本的不断更新和语言新功能的添加,越来越多被用于独立的、大型项目的开发。

Python还是一门解释型的编程语言,Python也是面向对象的编程语言。对比其他编程语言来说,Python入门要简单很多,更接近自然语言和正常思维方法,可以直接应用到工作中。同时当我们学习Python的时候非常容易上手,要比其他语言简单很多,几乎可以说是无所不能。

Python语言风格简介:

Python在设计上坚持了清晰划一的风格,这使得Python成为一门易读、易维护,并且被大量用户所欢迎的、用途广泛的语言。

对于一个特定的问题,只要有一种最好的方法来解决就好。这在由Tim Peters写的Python格言里面表述为:There should be one-- and preferably only one --obvious way to do it. 这正好和Perl语言的中心思想TMTOWTDI完全相反。

Python的作者有意的设计限制性很强的语法,使得不好的编程习惯都不能通过编译。其中很重要的一项就是Python的缩进规则。

‘柒’ python2.4的openpyxl1.1.5的style类用法

单元格可以使用渐变色缓迹好填充,style.color.start_color是渐变色的起始色,end_color是结束色,如果两个颜色相同,则单元格内就是一个颜色。就像下面这样。

importopenpyxl

fromopenpyxl.styleimportColor,州逗Fill
fromopenpyxl.cellimportget_column_letter
..

cell=sheet.cell(column=pt[0],row=pt[1])
cell.style.fill.fill_type=Fill.FILL_SOLID
cell.style.fill.start_color=Color(color)
扰铅cell.style.fill.end_color=Color(color)

‘捌’ style是python-docx库文档对象吗

不是。没有任何办法

‘玖’ python爬取网页数据怎样去除style

用正式则表达式,把style属性去除就好。

热点内容
sqllike字段 发布:2025-07-16 09:58:53 浏览:145
爱肤密码多少钱 发布:2025-07-16 09:52:51 浏览:616
如何访问电脑工作组 发布:2025-07-16 09:39:24 浏览:183
动态优先权算法 发布:2025-07-16 09:39:02 浏览:201
火车wifi密码是多少啊 发布:2025-07-16 09:35:46 浏览:756
sql的视图是从中导出的 发布:2025-07-16 09:31:34 浏览:784
安卓如何打开shell窗口 发布:2025-07-16 09:28:09 浏览:313
华为荣耀备忘录文件夹 发布:2025-07-16 09:23:23 浏览:972
基于特征匹配算法 发布:2025-07-16 09:18:23 浏览:46
梦香神奇宝贝服务器的ip 发布:2025-07-16 09:14:07 浏览:212