首页 文章 精选 留言 我的

精选列表

搜索[设置],共10023篇文章
优秀的个人博客,低调大师

python xlwt 设置 格式

转载自:关于写excel的格式控制,比如颜色等等 [ 复制代码 ](javascript:void(0); "复制代码") <pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;"> 1 import xlwt 2 from datetime import datetime 3 4 font0 = xlwt.Font() 5 font0.name = 'Times New Roman' 6 font0.colour_index = 2 7 font0.bold = True 8 9 style0 = xlwt.XFStyle() 10 style0.font = font0 11 12 style1 = xlwt.XFStyle() 13 style1.num_format_str = 'D-MMM-YY' 14 15 wb = xlwt.Workbook() 16 ws = wb.add_sheet('A Test Sheet') 17 18 ws.write(0, 0, 'Test', style0) 19 ws.write(1, 0, datetime.now(), style1) 20 ws.write(2, 0, 1) 21 ws.write(2, 1, 1) 22 ws.write(2, 2, xlwt.Formula("A3+B3")) 23 24 wb.save('example.xls')</pre> [ 复制代码 ](javascript:void(0); "复制代码") Examples Generating Excel Documents Using Python’s xlwt Here are some simple examples using Python’s xlwt library to dynamically generate Excel documents. Please note a useful alternative may be ezodf, which allows you to generate ODS (Open Document Spreadsheet) files for LibreOffice / OpenOffice. You can check them out at:http://packages.python.org/ezodf/index.html The Simplest Exampleimport xlwt workbook = xlwt.Workbook(encoding = 'ascii') worksheet = workbook.add_sheet('My Worksheet') worksheet.write(0, 0, label = 'Row 0, Column 0 Value') workbook.save('Excel_Workbook.xls') Formatting the Contents of a Cellimport xlwt workbook = xlwt.Workbook(encoding = 'ascii') worksheet = workbook.add_sheet('My Worksheet') font = xlwt.Font() # Create the Font font.name = 'Times New Roman' font.bold = True font.underline = True font.italic = True style = xlwt.XFStyle() # Create the Style style.font = font # Apply the Font to the Style worksheet.write(0, 0, label = 'Unformatted value') worksheet.write(1, 0, label = 'Formatted value', style) # Apply the Style to the Cell workbook.save('Excel_Workbook.xls') Attributes of the Font Objectfont.bold = True # May be: True, False font.italic = True # May be: True, False font.struck_out = True # May be: True, False font.underline = xlwt.Font.UNDERLINE_SINGLE # May be: UNDERLINE_NONE, UNDERLINE_SINGLE, UNDERLINE_SINGLE_ACC, UNDERLINE_DOUBLE, UNDERLINE_DOUBLE_ACC font.escapement = xlwt.Font.ESCAPEMENT_SUPERSCRIPT # May be: ESCAPEMENT_NONE, ESCAPEMENT_SUPERSCRIPT, ESCAPEMENT_SUBSCRIPT font.family = xlwt.Font.FAMILY_ROMAN # May be: FAMILY_NONE, FAMILY_ROMAN, FAMILY_SWISS, FAMILY_MODERN, FAMILY_SCRIPT, FAMILY_DECORATIVE font.charset = xlwt.Font.CHARSET_ANSI_LATIN # May be: CHARSET_ANSI_LATIN, CHARSET_SYS_DEFAULT, CHARSET_SYMBOL, CHARSET_APPLE_ROMAN, CHARSET_ANSI_JAP_SHIFT_JIS, CHARSET_ANSI_KOR_HANGUL, CHARSET_ANSI_KOR_JOHAB, CHARSET_ANSI_CHINESE_GBK, CHARSET_ANSI_CHINESE_BIG5, CHARSET_ANSI_GREEK, CHARSET_ANSI_TURKISH, CHARSET_ANSI_VIETNAMESE, CHARSET_ANSI_HEBREW, CHARSET_ANSI_ARABIC, CHARSET_ANSI_BALTIC, CHARSET_ANSI_CYRILLIC, CHARSET_ANSI_THAI, CHARSET_ANSI_LATIN_II, CHARSET_OEM_LATIN_I font.colour_index = ? font.get_biff_record = ? font.height = 0x00C8 # C8 in Hex (in decimal) = 10 points in height. font.name = ? font.outline = ? font.shadow = ? Setting the Width of a Cellimport xltw workbook = xlwt.Workbook() worksheet = workbook.add_sheet('My Sheet') worksheet.write(0, 0, 'My Cell Contents') worksheet.col(0).width = 3333 # 3333 = 1" (one inch). workbook.save('Excel_Workbook.xls') Entering a Date into a Cellimport xlwt import datetime workbook = xlwt.Workbook() worksheet = workbook.add_sheet('My Sheet') style = xlwt.XFStyle() style.num_format_str = 'M/D/YY' # Other options: D-MMM-YY, D-MMM, MMM-YY, h:mm, h:mm:ss, h:mm, h:mm:ss, M/D/YY h:mm, mm:ss, [h]:mm:ss, mm:ss.0 worksheet.write(0, 0, datetime.datetime.now(), style) workbook.save('Excel_Workbook.xls') Adding a Formula to a Cellimport xlwt workbook = xlwt.Workbook() worksheet = workbook.add_sheet('My Sheet') worksheet.write(0, 0, 5) # Outputs 5 worksheet.write(0, 1, 2) # Outputs 2 worksheet.write(1, 0, xlwt.Formula('A1*B1')) # Should output "10" (A1[5] * A2[2]) worksheet.write(1, 1, xlwt.Formula('SUM(A1,B1)')) # Should output "7" (A1[5] + A2[2]) workbook.save('Excel_Workbook.xls') Adding a Hyperlink to a Cellimport xlwt workbook = xlwt.Workbook() worksheet = workbook.add_sheet('My Sheet') worksheet.write(0, 0, xlwt.Formula('HYPERLINK("http://www.google.com";"Google")')) # Outputs the text "Google" linking to http://www.google.com workbook.save('Excel_Workbook.xls') Merging Columns and Rowsimport xlwt workbook = xlwt.Workbook() worksheet = workbook.add_sheet('My Sheet') worksheet.write_merge(0, 0, 0, 3, 'First Merge') # Merges row 0's columns 0 through 3. font = xlwt.Font() # Create Font font.bold = True # Set font to Bold style = xlwt.XFStyle() # Create Style style.font = font # Add Bold Font to Style worksheet.write_merge(1, 2, 0, 3, 'Second Merge', style) # Merges row 1 through 2's columns 0 through 3. workbook.save('Excel_Workbook.xls') Setting the Alignment for the Contents of a Cellimport xlwt workbook = xlwt.Workbook() worksheet = workbook.add_sheet('My Sheet') alignment = xlwt.Alignment() # Create Alignment alignment.horz = xlwt.Alignment.HORZ_CENTER # May be: HORZ_GENERAL, HORZ_LEFT, HORZ_CENTER, HORZ_RIGHT, HORZ_FILLED, HORZ_JUSTIFIED, HORZ_CENTER_ACROSS_SEL, HORZ_DISTRIBUTED alignment.vert = xlwt.Alignment.VERT_CENTER # May be: VERT_TOP, VERT_CENTER, VERT_BOTTOM, VERT_JUSTIFIED, VERT_DISTRIBUTED style = xlwt.XFStyle() # Create Style style.alignment = alignment # Add Alignment to Style worksheet.write(0, 0, 'Cell Contents', style) workbook.save('Excel_Workbook.xls') Adding Borders to a Cell# Please note: While I was able to find these constants within the source code, on my system (using LibreOffice,) I was only presented with a solid line, varying from thin to thick; no dotted or dashed lines. import xlwt workbook = xlwt.Workbook() worksheet = workbook.add_sheet('My Sheet') borders = xlwt.Borders() # Create Borders borders.left = xlwt.Borders.DASHED # May be: NO_LINE, THIN, MEDIUM, DASHED, DOTTED, THICK, DOUBLE, HAIR, MEDIUM_DASHED, THIN_DASH_DOTTED, MEDIUM_DASH_DOTTED, THIN_DASH_DOT_DOTTED, MEDIUM_DASH_DOT_DOTTED, SLANTED_MEDIUM_DASH_DOTTED, or 0x00 through 0x0D. borders.right = xlwt.Borders.DASHED borders.top = xlwt.Borders.DASHED borders.bottom = xlwt.Borders.DASHED borders.left_colour = 0x40 borders.right_colour = 0x40 borders.top_colour = 0x40 borders.bottom_colour = 0x40 style = xlwt.XFStyle() # Create Style style.borders = borders # Add Borders to Style worksheet.write(0, 0, 'Cell Contents', style) workbook.save('Excel_Workbook.xls') Setting the Background Color of a Cellimport xlwt workbook = xlwt.Workbook() worksheet = workbook.add_sheet('My Sheet') pattern = xlwt.Pattern() # Create the Pattern pattern.pattern = xlwt.Pattern.SOLID_PATTERN # May be: NO_PATTERN, SOLID_PATTERN, or 0x00 through 0x12 pattern.pattern_fore_colour = 5 # May be: 8 through 63\. 0 = Black, 1 = White, 2 = Red, 3 = Green, 4 = Blue, 5 = Yellow, 6 = Magenta, 7 = Cyan, 16 = Maroon, 17 = Dark Green, 18 = Dark Blue, 19 = Dark Yellow , almost brown), 20 = Dark Magenta, 21 = Teal, 22 = Light Gray, 23 = Dark Gray, the list goes on... style = xlwt.XFStyle() # Create the Pattern style.pattern = pattern # Add Pattern to Style worksheet.write(0, 0, 'Cell Contents', style) workbook.save('Excel_Workbook.xls') TODO: Things Left to Document `- Panes -- separate views which are always in view Border Colors (documented above, but not taking effect as it should) Border Widths (document above, but not working as expected) Protection Row Styles Zoom / Manification WS Props? Source Code for reference available at: https://secure.simplistix.co.uk/svn/xlwt/trunk/xlwt/`

优秀的个人博客,低调大师

DOCKER网络代理设置

在一些实验室环境,服务器没有直接连接外网的权限,需要通过网络代理。我们通常会将网络代理直接配置在/etc/environment、/etc/profile之类的配置文件中,这对于大部分操作都是可行的。然而,docker命令却使用不了这些代理。比如docker pull时需要从外网下载镜像,就会出现如下错误: $dockerpullhello-world Unabletofindimage'hello-world:latest'locally Pullingrepositorydocker.io/library/hello-world docker:Networktimedoutwhiletryingtoconnecttohttps://index.docker.io/v1/repositories/library/hello-world/images.Youmaywanttocheckyourinternetconnectionorifyouarebehindaproxy..See'dockerrun--help'. ps: 本文在Ubuntu16.04下测试通过。 解决方案一: 停止docker服务,手动以使用2375端口监听所有网络接口的方式启动docker daemon。 $systemctlstopdocker.service $nohupdockerdaemon-Htcp://0.0.0.0:2375-Hunix:///var/run/docker.sock& 详情参见:*https://docs.docker.com/v1.11/engine/reference/commandline/daemon/#daemon-socket-option* 解决方案二: 编辑配置文件,Ubuntu下是/etc/default/docker,CentOS下是/etc/sysconfig/docker。不过通过修改这两个文件来配置daemon已经是discouraged的了。不鼓励使用这种方法。 HTTP_PROXY="http://[proxy-addr]:[proxy-port]/"HTTPS_PROXY="https://[proxy-addr]:[proxy-port]/"exportHTTP_PROXYHTTPS_PROXY 解决方案三: 该方法是持久化的,修改后会一直生效。该方法覆盖了默认的docker.service文件。 1. 为docker服务创建一个内嵌的systemd目录 $mkdir-p/etc/systemd/system/docker.service.d 2. 创建/etc/systemd/system/docker.service.d/http-proxy.conf文件,并添加HTTP_PROXY环境变量。其中[proxy-addr]和[proxy-port]分别改成实际情况的代理地址和端口: [Service]Environment="HTTP_PROXY=http://[proxy-addr]:[proxy-port]/""HTTPS_PROXY=https://[proxy-addr]:[proxy-port]/" 3. 如果还有内部的不需要使用代理来访问的Docker registries,那么嗨需要制定NO_PROXY环境变量: [Service]Environment="HTTP_PROXY=http://[proxy-addr]:[proxy-port]/""HTTPS_PROXY=https://[proxy-addr]:[proxy-port]/""NO_PROXY=localhost,127.0.0.1,docker-registry.somecorporation.com" 4. 更新配置: $systemctldaemon-reload 5. 重启Docker服务: $systemctlrestartdocker 本文转自zsdnr 51CTO博客,原文链接:http://blog.51cto.com/12942149/1929357,如需转载请自行联系原作者

优秀的个人博客,低调大师

ES线程池设置

每个Elasticsearch节点内部都维护着多个线程池,如index、search、get、bulk等,用户可以修改线程池的类型和大小,线程池默认大小跟CPU逻辑一致 一、查看当前线程组状态 curl -XGET 'http://localhost:9200/_nodes/stats?pretty' "thread_pool" : { "bulk" : { "threads" : 32, "queue" : 0, "active" : 0, "rejected" : 0, "largest" : 32, "completed" : 659997 }, "index" : { "threads" : 2, "queue" : 0, "active" : 0, "rejected" : 0, "largest" : 2, "completed" : 2 } 上面截取了部分线程池的配置,其中,最需要关注的是rejected。当某个线程池active==threads时,表示所有线程都在忙,那么后续新的请求就会进入queue中,即queue>0,一旦queue大小超出限制,如bulk的queue默认50,那么elasticsearch进程将拒绝请求(碰到bulk HTTP状态码429),相应的拒绝次数就会累加到rejected中。 解决方法是 1、记录失败的请求并重发 2、减少并发写的进程个数,同时加大每次bulk请求的size 二、核心线程池 index:此线程池用于索引和删除操作。它的类型默认为fixed,size默认为可用处理器的数量,队列的size默认为300。 search:此线程池用于搜索和计数请求。它的类型默认为fixed,size默认为可用处理器的数量乘以3,队列的size默认为1000。 suggest:此线程池用于建议器请求。它的类型默认为fixed,size默认为可用处理器的数量,队列的size默认为1000。 get:此线程池用于实时的GET请求。它的类型默认为fixed,size默认为可用处理器的数量,队列的size默认为1000。 bulk:此线程池用于批量操作。它的类型默认为fixed,size默认为可用处理器的数量,队列的size默认为50。 percolate:此线程池用于预匹配器操作。它的类型默认为fixed,size默认为可用处理器的数量,队列的size默认为1000。 三、线程池类型 1、cache 无限制的线程池,为每个请求创建一个线程 2、fixed 有着固定大小的线程池,大小由size属性指定,允许你指定一个队列(使用queue_size属性指定)用来保存请求,直到有一个空闲的线程来执行请求。如果Elasticsearch无法把请求放到队列中(队列满了),该请求将被拒绝 四、修改线程池配置 1、elasticsearch.yml threadpool.index.type: fixed threadpool.index.size: 100 threadpool.index.queue_size: 500 2、Rest API curl -XPUT 'localhost:9200/_cluster/settings' -d '{ "transient": { "threadpool.index.type": "fixed", "threadpool.index.size": 100, "threadpool.index.queue_size": 500 } }' 五、bulk异常排查 使用es bulk api时报错如下 EsRejectedExcutionException[rejected execution(queue capacity 50) on.......] 这个错误明显是默认大小为50的队列(queue)处理不过来了,解决方法是增大bulk队列的长度 elasticsearch.yml threadpool.bulk.queue_size: 1000 相关文档 https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-nodes-stats.html https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-threadpool.html 本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/bonelee/p/7840629.html,如需转载请自行联系原作者

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

用户登录
用户注册