當前位置: 首頁>>代碼示例>>Python>>正文


Python copy.copy方法代碼示例

本文整理匯總了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("數據重複") 
開發者ID:czy1999,項目名稱:weibo-topic-spider,代碼行數:27,代碼來源:excelSave.py

示例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) 
開發者ID:epolestar,項目名稱:equant,代碼行數:27,代碼來源:TestExcel.py

示例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) 
開發者ID:epolestar,項目名稱:equant,代碼行數:18,代碼來源:TestExcel2.py

示例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) 
開發者ID:Scemoon,項目名稱:lpts,代碼行數:23,代碼來源:test_copy.py

示例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 
開發者ID:jiajunsu,項目名稱:calculator_of_Onmyoji,代碼行數:13,代碼來源:result_combination.py

示例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格式表格【追加】寫入數據成功!") 
開發者ID:yzy1996,項目名稱:Python-Code,代碼行數:15,代碼來源:pdf2excel.py

示例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)) 
開發者ID:shengqiangzhang,項目名稱:examples-of-web-crawlers,代碼行數:14,代碼來源:excel_func.py

示例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') 
開發者ID:xulabs,項目名稱:aitom,代碼行數:9,代碼來源:sa.py

示例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)   #覆蓋保存(注意編碼錯誤) 
開發者ID:gitjayzhen,項目名稱:AppiumTestProject,代碼行數:8,代碼來源:ExcelDataUtil.py

示例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

    # 添加表 
開發者ID:will4906,項目名稱:PatentCrawler,代碼行數:13,代碼來源:ExcelUtil.py

示例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 
開發者ID:PCWG,項目名稱:PCWG,代碼行數:16,代碼來源:data_sharing_reports.py

示例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 
開發者ID:PCWG,項目名稱:PCWG,代碼行數:58,代碼來源:data_sharing_reports.py


注:本文中的xlutils.copy.copy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。