本文整理汇总了Python中xlutils.copy.copy方法的典型用法代码示例。如果您正苦于以下问题:Python copy.copy方法的具体用法?Python copy.copy怎么用?Python copy.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xlutils.copy
的用法示例。
在下文中一共展示了copy.copy方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: write_excel_xls_append_norepeat
# 需要导入模块: from xlutils import copy [as 别名]
# 或者: from xlutils.copy import copy [as 别名]
def write_excel_xls_append_norepeat(path, value):
workbook = xlrd.open_workbook(path) # 打开工作簿
sheets = workbook.sheet_names() # 获取工作簿中的所有表格
worksheet = workbook.sheet_by_name(sheets[0]) # 获取工作簿中所有表格中的的第一个表格
rows_old = worksheet.nrows # 获取表格中已存在的数据的行数
new_workbook = copy(workbook) # 将xlrd对象拷贝转化为xlwt对象
new_worksheet = new_workbook.get_sheet(0) # 获取转化后工作簿中的第一个表格
rid = 0
for i in range(0, len(value)):
data = read_excel_xls(path)
data_temp = []
for m in range(0,len(data)):
data_temp.append(data[m][1:len(data[m])])
value_temp = []
for m in range(0,len(value)):
value_temp.append(value[m][1:len(value[m])])
if value_temp[i] not in data_temp:
for j in range(0, len(value[i])):
new_worksheet.write(rid+rows_old, j, value[i][j]) # 追加写入数据,注意是从i+rows_old行开始写入
rid = rid + 1
new_workbook.save(path) # 保存工作簿
print("xls格式表格【追加】写入数据成功!")
else:
print("数据重复")
示例2: handle_data
# 需要导入模块: from xlutils import copy [as 别名]
# 或者: from xlutils.copy import copy [as 别名]
def handle_data(context):
global g_contList
#跳过回测阶段
if context.triggerType() == 'H':
return
#追加写入excel表
r_xls = xlrd.open_workbook(wt_ex_file) # 读取excel文件
row = r_xls.sheets()[0].nrows # 获取已有的行数
excel = copy(r_xls) # 将xlrd的对象转化为xlwt的对象
wt_table = excel.get_sheet(0) # 获取要操作的sheet
#保存合约号、最新价、成交量、买卖价、买卖量到excel表格中
for cont in g_contList:
LogInfo(cont)
wt_table.write(row, 0, cont)
wt_table.write(row, 1, Q_UpdateTime(cont))
wt_table.write(row, 2, Q_Last(cont))
wt_table.write(row, 3, Q_BidPrice(cont))
wt_table.write(row, 4, Q_AskPrice(cont))
wt_table.write(row, 5, Q_TotalVol(cont))
wt_table.write(row, 6, Q_BidVol(cont))
wt_table.write(row, 7, Q_AskVol(cont))
row += 1
excel.save(wt_ex_file)
示例3: Write
# 需要导入模块: from xlutils import copy [as 别名]
# 或者: from xlutils.copy import copy [as 别名]
def Write(self, sheet, row, data):
'''更新写入'''
if not isinstance(data, list):
return
rdxls = xlrd.open_workbook(self._fullname)
wtxls = copy(rdxls)
if sheet not in rdxls.sheet_names():
tables = wtxls.add_sheet(sheet)
else:
tables = wtxls.get_sheet(sheet)
for i in range(len(data)):
tables.write(row, i, data[i])
wtxls.save(self._fullname)
示例4: test_copy_xlrd
# 需要导入模块: from xlutils import copy [as 别名]
# 或者: from xlutils.copy import copy [as 别名]
def test_copy_xlrd(self,c,xlwtw):
inwb = object()
outwb = Mock()
xlwtwi = Mock()
xlwtwi.output=[('junk',outwb)]
xlwtw.return_value=xlwtwi
self.failUnless(copy(inwb) is outwb)
self.assertEqual(len(c.call_args_list),1)
args = c.call_args_list[0][0]
self.assertEqual(len(args),2)
r = args[0]
self.failUnless(isinstance(r,XLRDReader))
self.failUnless(r.wb is inwb)
self.assertEqual(r.filename,'unknown.xls')
w = args[1]
self.failUnless(w is xlwtwi)
示例5: __init__
# 需要导入模块: from xlutils import copy [as 别名]
# 或者: from xlutils.copy import copy [as 别名]
def __init__(self, filename, postfix):
self.filename = filename
self.postfix = str(postfix)
read_book = xlrd.open_workbook(filename=self.filename)
self.write_book = copy(read_book)
self.work_sheet = None
self.work_sheet_num = 0
self.row_num = 0
self.count = 0
示例6: write_excel_xls_append
# 需要导入模块: from xlutils import copy [as 别名]
# 或者: from xlutils.copy import copy [as 别名]
def write_excel_xls_append(path, value):
index = len(value) # 获取需要写入数据的行数
workbook = xlrd.open_workbook(path) # 打开工作簿
sheets = workbook.sheet_names() # 获取工作簿中的所有表格
worksheet = workbook.sheet_by_name(sheets[0]) # 获取工作簿中所有表格中的的第一个表格
rows_old = worksheet.nrows # 获取表格中已存在的数据的行数
new_workbook = copy(workbook) # 将xlrd对象拷贝转化为xlwt对象
new_worksheet = new_workbook.get_sheet(0) # 获取转化后工作簿中的第一个表格
for i in range(0, index):
for j in range(0, len(value[i])):
new_worksheet.write(i+rows_old, j, value[i][j]) # 追加写入数据,注意是从i+rows_old行开始写入
new_workbook.save(path) # 保存工作簿
print("xls格式表格【追加】写入数据成功!")
示例7: write_excel_xls_append
# 需要导入模块: from xlutils import copy [as 别名]
# 或者: from xlutils.copy import copy [as 别名]
def write_excel_xls_append(path, sheet_name, value):
index = len(value) # 获取需要写入数据的行数
workbook = xlrd.open_workbook(path) # 打开工作簿
worksheet = workbook.sheet_by_name(sheet_name) # 获取工作簿中所有表格中的的第一个表格
rows_old = worksheet.nrows # 获取表格中已存在的数据的行数
new_workbook = copy(workbook) # 将xlrd对象拷贝转化为xlwt对象
new_worksheet = new_workbook.get_sheet(sheet_name) # 获取转化后工作簿中的第一个表格
for i in range(0, index):
for j in range(0, len(value[i])):
new_worksheet.write(i + rows_old, j, value[i][j]) # 追加写入数据,注意是从i+rows_old行开始写入
new_workbook.save(path) # 保存工作簿
print("{}【追加】写入【{}】数据成功!".format(path, sheet_name))
示例8: write_to_excel
# 需要导入模块: from xlutils import copy [as 别名]
# 或者: from xlutils.copy import copy [as 别名]
def write_to_excel(sheet, x, y, value): #x->col, y->row
rb = open_workbook('record.xls')
rs = rb.sheet_by_index(sheet)
wb = copy(rb)
ws = wb.get_sheet(sheet)
ws.write(y, x, value)
wb.save('record.xls')
示例9: writ_excel
# 需要导入模块: from xlutils import copy [as 别名]
# 或者: from xlutils.copy import copy [as 别名]
def writ_excel(self, row, column, value):
x_data = xlrd.open_workbook(self.excel_path, "rb") #只能是xls文件
copy_sheet = copy(x_data) #copy,并对附件进行操作
write_xls = copy_sheet.get_sheet(0) #得到附件中的sheet页
write_xls.write(row, column, value) #将测试的结果追加到附件中sheet页中每一行的后面
copy_sheet.save(self.excel_path) #覆盖保存(注意编码错误)
示例10: getExcel
# 需要导入模块: from xlutils import copy [as 别名]
# 或者: from xlutils.copy import copy [as 别名]
def getExcel(self, mode): # 采用工厂模式建立excel的读写实例
if isinstance(mode, str):
if mode.upper() == "READ":
return xlrd.open_workbook(self.__fileName)
elif mode.upper() == "WRITE":
rb = xlrd.open_workbook(self.__fileName)
return copy(rb)
else:
return None
# 添加表
示例11: copy_sheet
# 需要导入模块: from xlutils import copy [as 别名]
# 或者: from xlutils.copy import copy [as 别名]
def copy_sheet(self, workbook, source_index):
'''
workbook == source + book in use
source_index == index of sheet you want to copy (0 start)
new_name == name of new copied sheet
return: copied sheet
'''
source_worksheet = workbook.get_sheet(source_index)
copied_sheet = deepcopy(source_worksheet)
return copied_sheet
示例12: __init__
# 需要导入模块: from xlutils import copy [as 别名]
# 或者: from xlutils.copy import copy [as 别名]
def __init__(self, analysis, version, output_fname, pcwg_inner_ranges, share_name, export_time_series=False):
template_path = PathBuilder.get_path('Share_X_template.xls')
self.analysis = analysis
self.sheet_map = {}
self.export_time_series = export_time_series
if len(analysis.datasetConfigs) > 1:
raise Exception("Analysis must contain one and only one dataset")
Status.add("Loading template: {0}".format(template_path))
rb = xlrd.open_workbook(template_path, formatting_info=True)
wb = copy(rb)
Status.add("Setting up worksheets")
self.map_sheet(wb, "Submission")
self.map_sheet(wb, "Meta Data")
Status.add('Setting up baseline worksheet')
templates_to_finish = []
templates_to_finish.append(('Baseline', self.add_template_sheet(wb, 'Template')))
sheet_count = 1
for correction_name in analysis.corrections:
correction = analysis.corrections[correction_name]
Status.add(
'Setting up correction sheet worksheet: {0} of {1}'.format(sheet_count, len(analysis.corrections)))
templates_to_finish.append((correction.short_correction_name, self.add_template_sheet(wb, 'Template')))
sheet_count += 1
# note: attaching copied sheets to workbook after they are all copied seems
# seems to manage memory better which avoids a memory error in deepcopy
Status.add('Finishing Template Sheets')
sheet_count = 1
for template_to_finish in templates_to_finish:
Status.add(
'Finishing Template Sheets: {0} of {1}'.format(sheet_count, len(analysis.corrections)))
wb._Workbook__worksheets.append(template_to_finish[1])
template_to_finish[1].set_name(template_to_finish[0])
self.sheet_map[template_to_finish[0]] = template_to_finish[1]
sheet_count += 1
Status.add("Deleting template worksheets")
self.delete_template_sheet(wb, 'Template')
self.workbook = wb
self.output_fname = output_fname
self.version = version
self.pcwg_inner_ranges = pcwg_inner_ranges
self.share_name = share_name