本文整理匯總了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