繁体   English   中英

如何在python中使用xlrd检查单元格是否具有公式?

[英]How to check if cell has formula or not using xlrd in python?

我想从excel工作簿访问具有公式的单元格。 我有一个脚本,可以正常工作,但只能从excel读取数据。

我只需要用公式打印单元格。 一个例子将不胜感激。

下面的函数怎么样:-输入参数,您需要像下面那样传递下面的函数:-

Input Parameter:- validateExcelData("Desktop/test.xls,55")

注意 :-这里55是使用公式的计数,如果条件不起作用并且您将得到结果失败,则此操作在下面进行;但是,如果整数值不包含公式,则条件将起作用并且您将通过结果。 同样,这也不是有效的代码。 只要看看是否有帮助:)

def validateExcelData(input):
    inputParam=input.split(",")
    filePath=inputParam[0].strip()
    value=inputParam[1].strip()
    outputParams="Fail"
    try:
        fs = os.sep.join((os.path.expanduser("~"),filePath))
        wb=xlrd.open_workbook(fs)
        for s in wb.sheets():
            for row in range(s.nrows):
                for col in range(s.ncols):
                    if s.cell(row,col).value==int(value):
                        outputParams ="PASS"
                        break
    except:
        outputParams = GetException()


    return outputParams

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM