python处理存在的excel,保持原格式输出的方法

#!/usr/bin/env python
# coding: utf-8

# In[63]:


import xlrd, xlwt
from xlutils.copy import copy
import time
import os

################################这部分是最主要的一部分


def setOutCell(outSheet, row, col, value):
    """ Change cell value without changing formatting. """

    def _getOutCell(outSheet, rowIndex, colIndex):
        """ HACK: Extract the internal xlwt cell representation. """
        row = outSheet._Worksheet__rows.get(rowIndex)
        if not row: return None

        cell = row._Row__cells.get(colIndex)
        return cell

    # HACK to retain cell style.
    previousCell = _getOutCell(outSheet, row, col)
    # END HACK, PART I

    outSheet.write(row, col, value)

    # HACK, PART II
    if previousCell:
        newCell = _getOutCell(outSheet, row, col)
        if newCell:
            newCell.xf_idx = previousCell.xf_idx

################################

def read_excel():
    # 打开文件
    rdworkBook = xlrd.open_workbook('table.xls', formatting_info=True);
    
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值