{"id":1708,"date":"2020-06-22T17:35:24","date_gmt":"2020-06-22T09:35:24","guid":{"rendered":"http:\/\/39.97.231.10\/?p=1708"},"modified":"2020-06-22T17:35:24","modified_gmt":"2020-06-22T09:35:24","slug":"%e4%bd%bf%e7%94%a8-openpyxl-%e8%ae%be%e7%bd%ae-excel-%e5%8d%95%e5%85%83%e6%a0%bc%e5%ad%97%e4%bd%93","status":"publish","type":"post","link":"http:\/\/www.weijing.co\/?p=1708","title":{"rendered":"\u4f7f\u7528 openpyxl \u8bbe\u7f6e Excel \u5355\u5143\u683c\u5b57\u4f53"},"content":{"rendered":"<div>\n\u9996\u5148\u4ece openpyxl.styles \u6a21\u5757\u4e2d\u5bfc\u5165 Font \u7c7b\uff1a<\/p>\n<div>\n<pre>import openpyxl\nfrom openpyxl.styles import Font\n<\/pre>\n<\/div>\n<p>\u7136\u540e\u5efa\u7acb Font \u5bf9\u8c61\uff0c\u901a\u8fc7\u5b83\u6765\u786e\u5b9a\u6587\u672c\u5728\u5355\u5143\u683c\u4e2d\u7684\u663e\u793a\u6837\u5f0f\u3002Font \u7c7b\u652f\u6301\u4ee5\u4e0b\u5c5e\u6027\uff1a\n<\/p><\/div>\n<div>\n<table>\n<thead>\n<tr>\n<th>\u53c2\u6570<\/th>\n<th>\u7c7b\u578b<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>name<\/td>\n<td>\u5b57\u7b26\u4e32<\/td>\n<td>\u5b57\u4f53\u540d\u79f0\u3002\u6ce8\u610f\uff1a \u5982\u679c\u662f\u4e2d\u6587\u5b57\u4f53\uff0c\u524d\u9762\u5fc5\u987b\u52a0 u \u5bf9\u5176\u8fdb\u884c Unicode \u7f16\u7801\u3002<\/td>\n<\/tr>\n<tr>\n<td>size<\/td>\n<td>\u6574\u578b<\/td>\n<td>\u5b57\u4f53\u5927\u5c0f\u3002<\/td>\n<\/tr>\n<tr>\n<td>bold<\/td>\n<td>\u5e03\u5c14\u578b<\/td>\n<td>\u662f\u5426\u4e3a\u7c97\u4f53\u3002<\/td>\n<\/tr>\n<tr>\n<td>italic<\/td>\n<td>\u5e03\u5c14\u578b<\/td>\n<td>\u662f\u5426\u4e3a\u659c\u4f53\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div>\n<pre>import openpyxl\nfrom openpyxl.styles import Font\nwb = openpyxl.Workbook()\nsheet = wb[\\'Sheet\\']\n# \u5b57\u4f53\u5bf9\u8c61\nfontObj1 = Font(name=u\\'\u5fae\u8f6f\u96c5\u9ed1\\', bold=True, italic=True, size=24)\nsheet[\\'A1\\'].font = fontObj1\nsheet[\\'A1\\'] = \\'\u5fae\u8f6f\u96c5\u9ed1\u3001\u7c97\u4f53\u3001\u659c\u4f53\u3001\u5b57\u4f53\u5927\u5c0f\u4e3a 24\\'\nfontObj2 = Font(name=u\\'\u96b6\u4e66\\', bold=False, italic=False, size=32)\nsheet[\\'A2\\'].font = fontObj2\nsheet[\\'A2\\'] = \\'\u96b6\u4e66\u3001\u5b57\u4f53\u5927\u5c0f\u4e3a 32\\'\nwb.save(\\'styles.xlsx\\')\n<\/pre>\n<\/div>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<div>\n<div>\n<div><\/div>\n<div data-width=\\\"660\\\" data-height=\\\"178\\\"><img src=\\\"\/\/upload-images.jianshu.io\/upload_images\/3386108-9ed4bd8ae7bea52e.png?imageMogr2\/auto-orient\/strip|imageView2\/2\/w\/660\/format\/webp\\\" data-original-src=\\\"\/\/upload-images.jianshu.io\/upload_images\/3386108-9ed4bd8ae7bea52e.png\\\" data-original-width=\\\"660\\\" data-original-height=\\\"178\\\" data-original-format=\\\"image\/png\\\" data-original-filesize=\\\"18292\\\" data-image-index=\\\"1\\\" \/><\/div>\n<\/div>\n<div><\/div>\n<\/div>\n<p>\u6211\u4eec\u5c06 Font \u5bf9\u8c61\u4f20\u9012\u7ed9 Cell \u5bf9\u8c61\u7684 font \u5c5e\u6027\uff0c\u5373\u53ef\u8bbe\u7f6e\u5176\u5b57\u4f53<span style=\\\"font-size: 1rem;\\\">\u3002<\/span>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u9996\u5148\u4ece openpyxl.styles \u6a21\u5757\u4e2d\u5bfc\u5165 Font \u7c7b\uff1a import openpyxl from  &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.weijing.co\/?p=1708\"> <span class=\"screen-reader-text\">\u4f7f\u7528 openpyxl \u8bbe\u7f6e Excel \u5355\u5143\u683c\u5b57\u4f53<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[106,126],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"mailpoet_newsletter_max":false,"woocommerce_thumbnail":false,"woocommerce_single":false,"woocommerce_gallery_thumbnail":false,"shop_catalog":false,"shop_single":false,"shop_thumbnail":false},"uagb_author_info":{"display_name":"weijing","author_link":"http:\/\/www.weijing.co\/?author=4"},"uagb_comment_info":0,"uagb_excerpt":"\u9996\u5148\u4ece openpyxl.styles \u6a21\u5757\u4e2d\u5bfc\u5165 Font \u7c7b\uff1a import openpyxl from &hellip;","_links":{"self":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/1708"}],"collection":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1708"}],"version-history":[{"count":0,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/1708\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1708"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1708"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1708"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}