#!/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);
python处理存在的excel,保持原格式输出的方法
最新推荐文章于 2025-04-01 08:38:34 发布


4141

被折叠的 条评论
为什么被折叠?



