首页 文章 精选 留言 我的

精选列表

搜索[设置],共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,如需转载请自行联系原作者

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

设置Android程序图标

先在/res/drawable/目录下放一个叫icon.png的图标图片(48×48),并且在/res/values/strings.xml中定义app_name 修改<string name="app_name">你的程序名称</string>节点 工程的AndroidManifest.xml文件中添加 <applicationandroid:icon="@drawable/icon"android:label="@string/app_name"> 不需要加文件扩展名 本文转自欢醉博客园博客,原文链接http://www.cnblogs.com/zhangs1986/p/3261647.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 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。