脚本专栏 
首页 > 脚本专栏 > 浏览文章

Python 读取有公式cell的结果内容实例方法

(编辑:jimmy 日期: 2024/10/27 浏览:3 次 )

操作Excel通常是用如下三个扩展体:

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

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

就是加上 “data_only=True” 这个参数。

xlsxFileWithFullPath ---要操作的文件。

加上以后你会发现,还是依然如故,或者是时可时否!

如把文件打开,再保存一遍,执行程序,第一遍可以,第二遍就不行了!

其实, 关于 data_only=True 这个参数有个重要说明:

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

这就解释了上述时可时否的问题。

这样解决问题的办法就有了:用程序来完成那个保存文件的任务即可!

(1)

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

[!!]just open and save the file once! why"Excel.Application")
xlApp.Visible = False
xlBook = xlApp.Workbooks.Open(file_name)
xlBook.Save()
xlBook.Close()

问题是解决了,速度就是有点慢!

以上就是本次介绍的全部相关知识点,感谢大家的学习,欢迎转载。

上一篇:TensorFlow通过文件名/文件夹名获取标签,并加入队列的实现
下一篇:Django 项目通过加载不同env文件来区分不同环境
一句话新闻
Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 SiteMap