티스토리 뷰

SWDesk

[Python] Example for Excel Spreadsheet

bizmaker 2020. 12. 30. 23:46

"pip install openpyxl"

 

 

import openpyxl
# Extension : 'xlsx'
class cBSpread:

    def __init__(self):
        self.WorkBook = openpyxl.Workbook()

    def CreateSpreadFile(self, fileName):
        self.SpreadFile = openxl.load_workbook(fileName)

    def WriteSearchedInfos(self, sheetName, searchedInfos):
        #workSheet = self.WorkBook.get_sheet_by_name(sheetName)
        #workSheet = self.WorkBook[sheetName]
        workSheet = self.WorkBook.create_sheet(sheetName)
        rowIndex = 2
        colIndex = 2
        count11 = 0
        for searchedInfo in searchedInfos:
            linkAddress1 = searchedInfo['address']
            linkTitle1 = searchedInfo['title']
            linkBody1 = searchedInfo['body']
            count21 = 0
            overlapped1 = False
            for cellInfo2 in searchedInfos:
                if(count21 >= count11):
                    break
                if linkAddress1 == cellInfo2['address']:
                    overlapped1 = True
                    break
                count21 += 1
            if not overlapped1:
                workSheet.cell(rowIndex, colIndex).value = linkAddress1
                workSheet.cell(rowIndex, colIndex+1).value = linkTitle1
                workSheet.cell(rowIndex, colIndex+2).value = linkBody1
                rowIndex += 1
            count11 += 1

    def Close(self, fileName):
        self.WorkBook.save(fileName)

    def SaveAsSpreadFile(self, newFilename):
        self.WorkBook.save(newFilename)
반응형
반응형
250x250
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함