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

作者:paeser 时间:2021-09-06 21:07:11 

操作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? 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()

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

来源:https://blog.51cto.com/12619048/2471418

标签:Python,cell
0
投稿

猜你喜欢

  • Python lambda表达式原理及用法解析

    2021-03-02 18:52:12
  • 修改新云CMS底部版权信息字数限制

    2008-07-31 18:00:00
  • ASP访问数量统计代码

    2011-04-08 10:59:00
  • JSP 开发之 releaseSession的实例详解

    2023-06-14 11:49:03
  • Python的Flask站点中集成xhEditor文本编辑器的教程

    2023-04-05 00:41:06
  • Python安装docx依赖包教程

    2023-02-11 22:23:36
  • Python办公自动化之Excel介绍

    2021-04-19 11:06:07
  • OpenCV 图像梯度的实现方法

    2023-07-14 08:25:43
  • SQL Server与Oracle、DB2的优劣对比

    2009-01-07 14:16:00
  • Oracle RMAN快速入门指南

    2010-07-18 12:50:00
  • golang中net的tcp服务使用

    2023-08-30 10:54:14
  • 使用 Django Highcharts 实现数据可视化过程解析

    2022-12-27 19:18:51
  • python修改微信和支付宝步数的示例代码

    2021-08-31 08:45:06
  • Python pyecharts绘制词云图代码

    2021-03-18 03:17:08
  • 深入了解NumPy 高级索引

    2023-07-02 05:22:51
  • asp任何连接带密码的access数据库

    2008-04-29 21:36:00
  • python 图片验证码代码

    2023-07-22 00:33:19
  • PyTorch安装与基本使用详解

    2023-05-09 03:20:51
  • 表单特殊输入js验证

    2008-03-26 12:01:00
  • Python中利用pyqt5制作指针钟表显示实时时间(指针时钟)

    2023-04-30 22:11:13
  • asp之家 网络编程 m.aspxhome.com