欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python 讀取有公式cell的結(jié)果內(nèi)容實(shí)例方法

 更新時(shí)間:2020年02月17日 09:58:46   作者:paeser  
在本篇文章里小編給大家整理的是關(guān)于Python 如何讀取有公式cell的結(jié)果內(nèi)容,需要的朋友們可以學(xué)習(xí)下。

操作Excel通常是用如下三個(gè)擴(kuò)展體:

  1. import xlrd
  2. import xlwt
  3. import openpyxl

wb1 = openpyxl.load_workbook(xlsxFileWithFullPath, data_only=True)

就是加上 “data_only=True” 這個(gè)參數(shù)。

xlsxFileWithFullPath ---要操作的文件。

加上以后你會(huì)發(fā)現(xiàn),還是依然如故,或者是時(shí)可時(shí)否!

如把文件打開,再保存一遍,執(zhí)行程序,第一遍可以,第二遍就不行了!

其實(shí), 關(guān)于 data_only=True 這個(gè)參數(shù)有個(gè)重要說明:

# data_only (bool) – controls whether cells with formula have either the formula (default) or the value stored the last time Excel read the sheet

這就解釋了上述時(shí)可時(shí)否的問題。

這樣解決問題的辦法就有了:用程序來完成那個(gè)保存文件的任務(wù)即可!

(1)

def ReadLine(self, tip1, tip2, movingRC, fixedRC, RorC, totalCells, sheetName, xlsxFileWithFullPath):

[!!]just open and save the file once! why? see bellow!
xlsxDealer.`JustOpenAndSaveTheFile`(xlsxFileWithFullPath)

(2)

def JustOpenAndSaveTheFile(self, file_name):
from win32com.client import Dispatch
xlApp = Dispatch("Excel.Application")
xlApp.Visible = False
xlBook = xlApp.Workbooks.Open(file_name)
xlBook.Save()
xlBook.Close()

問題是解決了,速度就是有點(diǎn)慢!

以上就是本次介紹的全部相關(guān)知識(shí)點(diǎn),感謝大家的學(xué)習(xí),歡迎轉(zhuǎn)載。

相關(guān)文章

最新評(píng)論