• 请不要在回答技术问题时复制粘贴 AI 生成的内容
amiwrong123
V2EX  ›  程序员

哪种 Python 库 修改 excel 文件能保存原有格式?

  •  
  •   amiwrong123 · Aug 10, 2020 · 2394 views
    This topic created in 2128 days ago, the information mentioned may be changed or developed.

    https://www.jb51.net/article/139311.htm

    import xlrd 
    import xlwt 
    import xlutils 
    

    按照上面这种方式,修改是能修改,但是 excel 原来的格式全没了。

    需求就是根据每行内容,修改每行的某一个单元格内容。

    3 replies    2020-08-10 17:28:54 +08:00
    cocomaster
        1
    cocomaster  
       Aug 10, 2020
    openpyxl 可以做到只修改单元格的值

    excel = openpyxl.load_workbook(path)
    excel._active_sheet_index = 1
    sheet = excel.active
    sheet.cell(row=2, column=1, value="test Value")
    sheet.cell(row=2, column=2, value="4599.11")
    excel.save(path)
    benjix
        2
    benjix  
       Aug 10, 2020 via Android
    openpyxl
    joApioVVx4M4X6Rf
        3
    joApioVVx4M4X6Rf  
       Aug 10, 2020
    openpyxl
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   976 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 21:57 · PVG 05:57 · LAX 14:57 · JFK 17:57
    ♥ Do have faith in what you're doing.