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
投稿

猜你喜欢

  • 详解pyinstaller selenium python3 chrome打包问题

    2023-08-12 08:26:40
  • MySQL数据库设置远程访问权限方法小结

    2024-01-16 11:12:24
  • DenseNet121模型实现26个英文字母识别任务

    2023-08-22 13:15:22
  • Python实现将绝对URL替换成相对URL的方法

    2023-08-28 13:40:08
  • matplotlib之pyplot模块坐标轴标签设置使用(xlabel()、ylabel())

    2021-10-16 11:01:10
  • DB为何大量出现select @@session.tx_read_only 详解

    2024-01-15 15:26:15
  • 基于javascript实现表格的简单操作

    2024-04-30 08:55:24
  • SQL Server附加数据库时出现错误的处理方法

    2024-01-20 19:57:58
  • django模板语法学习之include示例详解

    2023-10-03 18:52:54
  • 使用Pycharm分段执行代码

    2021-09-04 13:24:14
  • PHP字符串前后字符或空格删除方法介绍

    2023-05-29 05:47:56
  • sql集合运算符使用方法

    2024-01-26 08:18:13
  • ACCESS模糊查询出现"内存溢出"

    2009-08-13 14:25:00
  • Python3.6安装及引入Requests库的实现方法

    2022-06-12 16:55:46
  • Python使用openpyxl读写excel文件的方法

    2021-02-06 07:24:37
  • Python MongoDB 插入数据时已存在则不执行,不存在则插入的解决方法

    2022-11-16 20:48:41
  • Oracle 数据表分区的策略

    2010-07-21 13:30:00
  • python实现维吉尼亚加密法

    2023-06-12 23:19:21
  • Python中遍历列表的方法总结

    2023-11-01 19:11:11
  • 用err.raise自定义错误信息

    2008-02-20 12:48:00
  • asp之家 网络编程 m.aspxhome.com