日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Python 操作 Excel 表格

發布時間:2023/12/18 python 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python 操作 Excel 表格 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Python 操作 Excel 表格

文章目錄

    • Python 操作 Excel 表格
      • 一、xlrd
      • 二、xlwt

python處理excel主要使用兩個模塊,一個是xlrd
另一個是xlwt

一、xlrd

這個模塊主要是實現讀取文件的功能

這個模塊最主要的一個函數是:
open_workbook

它的用法如下所示:

open_workbook(filename=None, logfile=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, verbosity=0, use_mmap=True, file_contents=None, encoding_override=None, formatting_info=False, on_demand=False, ragged_rows=False, ignore_workbook_corruption=False)

參數的解釋如下所示:

Open a spreadsheet file for data extraction.:param filename: The path to the spreadsheet file to be opened.:param logfile: An open file to which messages and diagnostics are written.:param verbosity: Increases the volume of trace material written to thelogfile.:param use_mmap:Whether to use the mmap module is determined heuristically.Use this arg to override the result.Current heuristic: mmap is used if it exists.:param file_contents:A string or an :class:`mmap.mmap` object or some other behave-alikeobject. If ``file_contents`` is supplied, ``filename`` will not be used,except (possibly) in messages.:param encoding_override:Used to overcome missing or bad codepage informationin older-version files. See :doc:`unicode`.:param formatting_info:The default is ``False``, which saves memory.In this case, "Blank" cells, which are those with their own formattinginformation but no data, are treated as empty by ignoring the file's``BLANK`` and ``MULBLANK`` records.This cuts off any bottom or right "margin" of rows of empty or blankcells.Only :meth:`~xlrd.sheet.Sheet.cell_value` and:meth:`~xlrd.sheet.Sheet.cell_type` are available.When ``True``, formatting information will be read from the spreadsheetfile. This provides all cells, including empty and blank cells.Formatting information is available for each cell.Note that this will raise a NotImplementedError when used with anxlsx file.:param on_demand:Governs whether sheets are all loaded initially or when demandedby the caller. See :doc:`on_demand`.:param ragged_rows:The default of ``False`` means all rows are padded out with empty cells sothat all rows have the same size as found in:attr:`~xlrd.sheet.Sheet.ncols`.``True`` means that there are no empty cells at the ends of rows.This can result in substantial memory savings if rows are of widelyvarying sizes. See also the :meth:`~xlrd.sheet.Sheet.row_len` method.:param ignore_workbook_corruption:This option allows to read corrupted workbooks.When ``False`` you may face CompDocError: Workbook corruption.When ``True`` that exception will be ignored.:returns: An instance of the :class:`~xlrd.book.Book` class.

一般只需要寫第一個參數就可以了,就是寫出文件的路徑

最后這個函數返回的是一個xlrd.book.Book對象,我們接下來就可以對這個對象進行操作了

對于這個對象,可以用索引或者名字來獲取表單

xls_0 = xlrd.open_workbook("filename")# 讀取表格文件new_sheet = xls_0.sheet_by_index(0)# 獲取表單

獲取表單以后,可以獲取表單中的每一個元素,我們直接用索引就可以了

代碼是:

xls_0 = xlrd.open_workbook("filename")# 讀取表格文件new_sheet = xls_0.sheet_by_index(0)# 獲取表單value_0 = new_sheet.cell(rowx, colx).value# 獲取元素的值

到此,這個模塊就介紹的差不多了

二、xlwt

xlwt是寫入excel表格的模塊,主要操作入下:

wb = xlwt.Workbook() # 創建 excel 表格sh = wb.add_sheet("sheetname") # 創建一個 表單sh.write(rowx, colx, content)# 在文件中進行寫入的操作wb.save(filename_or_stream)# 保存文件

這些即就是xlwt最主要的操作了啦

以上是一些表格的簡單操作,適合于入門學習的簡單介紹,希望對大家有一定的幫助了啦。

總結

以上是生活随笔為你收集整理的Python 操作 Excel 表格的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 四川一级毛毛片 | 噜噜色网 | 麻豆久久久午夜一区二区 | 六月婷婷在线 | 国产主播喷水 | 久久久av免费 | 日本aaa视频 | 欧美a在线播放 | 美日韩一级 | 亚洲熟妇色自偷自拍另类 | 伊人成人在线观看 | 国产三级精品在线观看 | 成人黄色免费观看 | 人物动物互动39集免费观看 | 精品久久久久久中文字幕人妻最新 | 嫩草视频在线免费观看 | 久久这里只精品 | 色爽爽一区二区三区 | 亚洲国产精品999 | 欧美极品jizzhd欧美仙踪林 | 午夜免费片 | 筱田优全部av免费观看 | 高hnp视频| 色月婷婷 | 亚洲一区二区精华 | 日批网站在线观看 | 亚洲综合色成人 | 绿色地狱在线观看 | 久久婷婷亚洲 | 日本成人高清 | 欧美极品jizzhd欧美 | 成人网免费看 | 91欧美激情一区二区三区成人 | 亚洲精品水蜜桃 | 国产经典一区二区三区 | 久久成人视屏 | 黄色网占 | 韩国电影一区二区三区 | 精品无码久久久久久久久 | 国产浮力第一页 | 免费看黄网站在线观看 | 国产精品xxx在线 | 欧美骚视频 | 天天干视频在线观看 | 国产一区二区三区四区三区四 | 最近免费高清mv | 久久久久人 | www.爱色av.com | 免费看av软件| 国产一区二区三区在线观看免费 | 精品国产成人亚洲午夜福利 | 顶级毛茸茸aaahd极品 | 你懂的国产 | 天堂8在线视频 | 人妻av一区二区 | 天堂av一区二区三区 | 天堂精品在线 | 涩涩网站在线 | 国产免费成人在线视频 | h色视频在线观看 | 国产免费视频一区二区三区 | 一级片久久久久 | 午夜免费播放观看在线视频 | 亚洲精品高清在线 | 精品国产网站 | 午夜国产一区二区 | 一区二区精品在线 | 国内精品久久久久久 | zjzjzjzjzj亚洲女人 | 97精品国产97久久久久久春色 | 人妻熟女一区二区aⅴ水 | 99热免费精品 | 欧美男优 | 黄瓜视频在线观看污 | 亚洲激情视频在线观看 | 久久久久久亚洲av无码专区 | 岳狂躁岳丰满少妇大叫 | 国产无限资源 | 麻豆影片 | 成人免费毛片嘿嘿连载 | 久久国产福利 | 手机免费在线观看av | 国产一级性生活 | 国产精品一区二区在线免费观看 | 日鲁鲁| 国产欧美日韩高清 | 伊人论坛 | 欧美日韩网 | 欧美日本韩国在线 | 国产一区二区激情 | 中文字幕av免费在线观看 | 中文字幕第十二页 | 国产午夜激情 | 亚洲一区在线免费观看 | 永久免费看mv网站入口78 | 日韩成人高清在线 | 国产精品VideoSex性欧美 | 一本一本久久a久久精品综合麻豆 | 国产56页|