python:openpyxl

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
python:openpyxl [2019/03/04 14:26] mumeiyamibitopython:openpyxl [2019/03/04 14:51] (現在) mumeiyamibito
行 28: 行 28:
       * ''ws'': ワークシートオブジェクト       * ''ws'': ワークシートオブジェクト
       * ''wb'': ワークブックオブジェクト       * ''wb'': ワークブックオブジェクト
-    * ワークシート名で選択<code python>wb["SHEET_NAME"]+    * ワークシート名で選択<code python>wb["SHEET_NAME"]</code>
   * ワークシート名の変更<code python>ws.title = "NAME"</code>   * ワークシート名の変更<code python>ws.title = "NAME"</code>
     * ''ws'': ワークシートオブジェクト     * ''ws'': ワークシートオブジェクト
行 83: 行 83:
       * ''ws'': ワークシートオブジェクト       * ''ws'': ワークシートオブジェクト
       * セルオブジェクトが格納されたタプルが列単位のジェネレータで返される。       * セルオブジェクトが格納されたタプルが列単位のジェネレータで返される。
-   * 例: すべてのセルを for で読み込む<code python>+    * 例: すべてのセルを for で読み込む<code python>
 for row in ws: for row in ws:
     for cell in row:     for cell in row:
行 89: 行 89:
 </code> </code>
       * ''ws'': ワークシートオブジェクト       * ''ws'': ワークシートオブジェクト
 +    * セルの表示形式を変更する (''cell'' はセルオブジェクト)。
 +      * 標準<code python>cell.number_format = openpyxl.styles.numbers.FORMAT_GENERAL</code>
 +        * 何も指定しない場合は、自動的にこのフォーマットになる。
 +      * 数値
 +        * 数値のデフォルト<code python>cell.number_format = openpyxl.styles.numbers.FORMAT_NUMBER</code>
 +        * 桁数を指定<code python>cell.number_format = "0.0_"</code>
 +          * ''0_''、''0.0_''、''0.00_'' のように桁数を指定する。
 +        * コンマ区切り<code python>cell.number_format = "#,##0.0_"</code>
 +          * 桁数指定の前に ''#,##'' を付ける。
 +      * パーセント表示<code python>cell.number_format = "0.0%"</code>
 +        * 数値の表記の後に ''%'' を付ける。
  
  
 ===== 参考サイト ===== ===== 参考サイト =====
   * [[https://note.nkmk.me/python-openpyxl-usage/ | PythonでExcelファイル(xlsx)を読み書きするopenpyxlの使い方 | note.nkmk.me]]   * [[https://note.nkmk.me/python-openpyxl-usage/ | PythonでExcelファイル(xlsx)を読み書きするopenpyxlの使い方 | note.nkmk.me]]
 +  * [[http://note.crohaco.net/2017/python-openpyxl-excel/ | [Python] openpyxl で Excel を操作してみた! - くろのて]]
 +  * [[https://pg-chain.com/python-excel-format | Python Excelのセルにフォーマットを指定する | 鎖プログラム]]
  
  
 {{tag>プログラミング}} {{tag>プログラミング}}
  
  • python/openpyxl.1551677176.txt.gz
  • 最終更新: 2019/03/04 14:26
  • by mumeiyamibito