![图片[1]-python如何清空excel单元格-uusu优素-乐高,模型,3d打印,编程](http://uusucn.zbbe.cn/wp-content/uploads/2024/01/5eb254dd9e4a8888.jpg)
python中可以通过为Excel赋空值来清空单元格。
示例:
单元格如下:

清空单元格代码如下:
importos
importwin32com
fromwin32com.clientimportconstantsasc#旨在直接使用VBA常数
current_address=os.path.abspath('.')
excel_address=os.path.join(current_address,"示例.xlsx")
print(current_address)
xl_app=win32com.client.gencache.EnsureDispatch("Excel.Application")#若想引用常数的话使用此法调用Excel
xl_app.Visible=False#是否显示Excel文件
wb=xl_app.Workbooks.Open(excel_address)
sht=wb.Worksheets(1)
sht.Name="示例"
rng_1=sht.Range(sht.Cells(2,1),sht.Cells(2,3))
rng_1.Value=""
rng_1.Interior.Pattern=c.xlNone
rng_1.Interior.TintAndShade=0
rng_1.Interior.PatternTintAndShade=0
wb.Save()
wb.Close()
执行结果:

© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END



















































暂无评论内容