本文整理汇总了Python中openpyxl.writer.excel.ExcelWriter.save方法的典型用法代码示例。如果您正苦于以下问题:Python ExcelWriter.save方法的具体用法?Python ExcelWriter.save怎么用?Python ExcelWriter.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openpyxl.writer.excel.ExcelWriter
的用法示例。
在下文中一共展示了ExcelWriter.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_dump
# 需要导入模块: from openpyxl.writer.excel import ExcelWriter [as 别名]
# 或者: from openpyxl.writer.excel.ExcelWriter import save [as 别名]
def save_dump(workbook, filename):
if workbook.worksheets == []:
workbook.create_sheet()
writer = ExcelWriter(workbook)
writer.comment_writer = DumpCommentWriter
writer.save(filename)
return True
示例2: main
# 需要导入模块: from openpyxl.writer.excel import ExcelWriter [as 别名]
# 或者: from openpyxl.writer.excel.ExcelWriter import save [as 别名]
def main():
if len(sys.argv) != 3:
print_help()
return
excel_file = Workbook()
excel_writer = ExcelWriter(workbook=excel_file)
sheet = excel_file.worksheets[0]
csv_file = open(sys.argv[1], "r")
row = 1
for line in csv_file:
line = line.strip().decode("utf-8", "ignore")
ary = line.split("@")
col = 1
for item in ary:
col_letter = get_column_letter(col)
sheet.cell("%s%s" % (col_letter, row)).value = "%s" % (item.encode("utf-8", "ignore"))
col = col + 1
row = row + 1
excel_writer.save(filename=sys.argv[2])
return
示例3: save_search_data
# 需要导入模块: from openpyxl.writer.excel import ExcelWriter [as 别名]
# 或者: from openpyxl.writer.excel.ExcelWriter import save [as 别名]
def save_search_data(get_list, session, location=0, num=0):
# location: 是否要获取目标地址,1获取,0不获取
wb = load_workbook(SAVE_FILE_NAME)
ew = ExcelWriter(wb)
ws = wb.get_sheet_by_name(SHEET_NAME)
for i in get_list:
i = i.encode('utf-8')
i += u''
if location == 0:
coordinate = None
else:
coordinate = get_location(i, session)
temp_replace = re.compile('<[\s\S]+?>')
i = temp_replace.sub(' ', i)
i += u'\n'
i = i.decode('string-escape').encode('gbk')
i = unicode(i, 'unicode-escape')
i = i.encode('utf-8')
if coordinate:
num += 1
longitude = coordinate[0]
latitude = coordinate[1]
ws.cell(row=num+1, column=2).value = longitude
ws.cell(row=num+1, column=3).value = latitude
ws.cell(row=num+1, column=1).value = i
elif num == 0:
num += 1
ws.cell(row=num+1, column=1).value = i
ew.save(SAVE_FILE_NAME)
print (num)
return num
示例4: wirteContent
# 需要导入模块: from openpyxl.writer.excel import ExcelWriter [as 别名]
# 或者: from openpyxl.writer.excel.ExcelWriter import save [as 别名]
def wirteContent(file, data, cell):
wb = load_workbook(file)
ew = ExcelWriter(wb)
ws = wb.get_sheet_by_name(wb.get_sheet_names()[0])
ws.cell(cell).value = data
ws.title = os.path.splitext(file)[0]
ew.save(file)
示例5: write_to_xlsx_file
# 需要导入模块: from openpyxl.writer.excel import ExcelWriter [as 别名]
# 或者: from openpyxl.writer.excel.ExcelWriter import save [as 别名]
def write_to_xlsx_file(content, keys, file_path):
if os.path.exists(file_path) == False:
createFile(file_path)
wb = openpyxl.Workbook()
ew = ExcelWriter(workbook=wb)
wsheet = wb.worksheets[0]
is_close = raw_input('please be sure to close your xlsx file (y/n)?')
if is_close != 'y':
print '未关闭文件,退出程序'
return
rows = [row for row in wsheet.iter_rows(get_content_range_in_xlsx(keys.__len__() + 1))]
rows[0][0].value = TITLE_ANDROID_KEY
rows[0][1].value = TITLE_CN_STRING_VALUE
rows[0][2].value = TITLE_EN_STRING_VALUE
rows[0][3].value = TITLE_REMARKS
for i in range(0, keys.__len__()):
rows[i + 1][0].value = keys[i]
rows[i + 1][1].value = content[keys[i]]
continue
# print rows[i + 1][0].value, rows[i + 1][1].value
ew.save(file_path)
return
示例6: save
# 需要导入模块: from openpyxl.writer.excel import ExcelWriter [as 别名]
# 或者: from openpyxl.writer.excel.ExcelWriter import save [as 别名]
def save(self, xls_file):
"""Save log items as Excel files.
Args:
xls_file (str): path to the Excel file.
"""
ew = ExcelWriter(workbook=self.ner_log_workbook)
ew.save(filename=xls_file)
示例7: write_excel
# 需要导入模块: from openpyxl.writer.excel import ExcelWriter [as 别名]
# 或者: from openpyxl.writer.excel.ExcelWriter import save [as 别名]
def write_excel(filename, sheetname,headings, data):
wb=Workbook()
ew=ExcelWriter(workbook=wb)
ws=wb.worksheets[0]
ws.title=sheetname
#begin to write the headings
row=1
for i,heading in enumerate(headings):
col=get_column_letter(i+1)
ws.cell('%s%s'%(col,row)).value='%s'%(heading)
for row,rowdata in enumerate(data):
for i,celldata in enumerate(rowdata):
col=get_column_letter(i+1)
ws.cell('%s%s'%(col,(row+2))).value='%s'%(celldata)
ew.save(filename)
示例8: txtToCSV
# 需要导入模块: from openpyxl.writer.excel import ExcelWriter [as 别名]
# 或者: from openpyxl.writer.excel.ExcelWriter import save [as 别名]
def txtToCSV(pdf, omit_pages):
for i, item in enumerate(pdf):
pages = layout.get_pages(item)
text = []
for index, page in enumerate(pages):
if index+1 not in omit_pages[i]:
text.append(page)
text = ''.join(text)
sents = sent_tokenize(text)
wb = Workbook()
ew = ExcelWriter(workbook=wb)
dest_filename = item.split('.')[0]+'.xlsx'
ws = wb.worksheets[0]
for index, line in enumerate(sents):
ws.cell(row=index, column=0).value = line
ew.save(filename=dest_filename)
示例9: export
# 需要导入模块: from openpyxl.writer.excel import ExcelWriter [as 别名]
# 或者: from openpyxl.writer.excel.ExcelWriter import save [as 别名]
def export(title,header,rows):
wb = Workbook()
ew = ExcelWriter(workbook = wb)
dest_filename = r'/opt/aoaola/web/html/excel/' + title +'.xlsx'
ws = wb.worksheets[0]
for x in range(1,len(header)+1):
col = get_column_letter(x)
ws.cell('%s%s'%(col, 1)).value = '%s' % (header[x-1])
for i in range(len(rows)):
assert len(rows[i]) == 6
for j in range(len(rows[i])):
ws.cell(row=i+1,column=j).value = rows[i][j]
ew.save(filename = dest_filename)
示例10: create
# 需要导入模块: from openpyxl.writer.excel import ExcelWriter [as 别名]
# 或者: from openpyxl.writer.excel.ExcelWriter import save [as 别名]
def create(self, tables, pdic):
doc = Workbook()
ew = ExcelWriter(workbook=doc)
for table in tables:
sheet = doc.worksheets[0]
sheet.title = table
i = 0
for port in tables[table]:
c = sheet.cell(row=0, column=i)
c.value = port + "[" + ` pdic[port][2] ` + "]"
i += 1
try:
ew.save(filename=self.file_name)
return True
except:
return False
示例11: Excel2007Write
# 需要导入模块: from openpyxl.writer.excel import ExcelWriter [as 别名]
# 或者: from openpyxl.writer.excel.ExcelWriter import save [as 别名]
class Excel2007Write():
excelWriter = path = workBook = sheet = None;
def __init__(self, path):
self.path = path
self.workBook = Workbook()
self.excelWriter = ExcelWriter(workbook=self.workBook)
def createSheet(self, index, name):
sheet = self.workBook.worksheets[index]
sheet.title = name
return sheet
def set(self, sheet_obj, x, y, value):
col = get_column_letter(x + 1)
sheet_obj.cell('%s%s' % (col, y + 1)).value = value
def save(self):
self.excelWriter.save(filename=path)
示例12: write_excel
# 需要导入模块: from openpyxl.writer.excel import ExcelWriter [as 别名]
# 或者: from openpyxl.writer.excel.ExcelWriter import save [as 别名]
def write_excel(directory,filename, sheetname,headings, data,comment=None):
wb=Workbook()
ew=ExcelWriter(workbook=wb)
ws=wb.worksheets[0]
ws.title=sheetname
#begin to write the headings
row=1
for i,heading in enumerate(headings):
col=get_column_letter(i+1)
ws.cell('%s%s'%(col,row)).value='%s'%(heading)
#write the cell content
for row,rowdata in enumerate(data):
for i,celldataKey in enumerate(rowdata):
col=get_column_letter(i+1)
ws.cell('%s%s'%(col,(row+2))).value='%s'%(rowdata[celldataKey])
if not os.path.exists(directory):
os.makedirs(directory)
ew.save(directory+filename)
示例13: sendExcel
# 需要导入模块: from openpyxl.writer.excel import ExcelWriter [as 别名]
# 或者: from openpyxl.writer.excel.ExcelWriter import save [as 别名]
def sendExcel(fileDir,matrixList,sheetNameList):
#check that input lists have same length (one sheet name for each matrix)
if len(matrixList) != len(sheetNameList):
print 'List of variables being exported and of sheet names must be equal.'
return
#Set up excel workbook
wb = Workbook()
ew = ExcelWriter(workbook = wb)
dest_filename = fileDir
#Create sheet and export data for every matrix being exported
for matrix,sheetN in zip(matrixList,sheetNameList):
ws = wb.create_sheet()
ws.title = sheetN
#For a matrix
if len(matrix.shape) == 2:
#Dump matrix in the Excel sheet
(r,c) = matrix.shape
for element in xrange(c):
col = get_column_letter(element+2) #2, so it will start printing on B
for row in xrange(r):
ws.cell('%s%s'%(col, row+2)).value = matrix[row][element]
#For a vector
elif len(matrix.shape) == 1:
r = matrix.shape
r = r[0]
col = get_column_letter(2) #2, so it will start printing on B
for row in xrange(r):
ws.cell('%s%s'%(col, row+2)).value = matrix[row]
else:
print 'Only exports matrices and vectors!'
print 'Weird element found. \n'
return
## #Create another sheet in same workbook and put Pi
## ws = wb.create_sheet()
## ws.title = 'Pi'
## ws.cell('F5').value = 3.14
ew.save(dest_filename)
print 'Matrix has been exported to Excel.'
示例14: XlsxExcel
# 需要导入模块: from openpyxl.writer.excel import ExcelWriter [as 别名]
# 或者: from openpyxl.writer.excel.ExcelWriter import save [as 别名]
class XlsxExcel(AbstractExcel):
'''处理Excel 2007的子类'''
eb = None
def __init__(self, excel_name):
AbstractExcel.__init__(self, excel_name)
def OpenExcel(self):
if not self.exists:
return False
self.wb = load_workbook(self.ename)
return self
def GetSheet(self, num):
self.sh = self.wb.get_sheet_by_name(self.wb.get_sheet_names()[int(num)])
return self
def GetRowsNum(self):
return self.sh.get_highest_row()
def GetColsNum(self):
return self.sh.get_highest_col()
def GetCell(self, _row, _column):
return str(self.sh.cell(row = _row, column = _column).value)
def CreateExcel(self):
self.eb = Workbook()
self.w_wb = ExcelWriter(workbook = self.eb)
return self
def CreateSheet(self, sheet_name):
self.w_sh = self.eb.worksheets[int(sheet_name)]
return self
def SetCell(self, _row, _column, content):
self.w_sh.cell(row = _row, column = _column).value = content
return self
def Save(self):
self.w_wb.save(filename = self.ename)
示例15: enumerate
# 需要导入模块: from openpyxl.writer.excel import ExcelWriter [as 别名]
# 或者: from openpyxl.writer.excel.ExcelWriter import save [as 别名]
#process each row from this subject's data file
inputRow = 2
dataEnded=False
for condN, cond in enumerate(subj.trialList):
#about this condition
thisSetSize=cond['setSize']
thisPresent= cond['present']
thisCondition = "set%i_%s" %(thisSetSize, thisPresent) #e.g. set6_y
#about this response
thisRT= subj.data['resp.rt'][condN]
thisAcc= subj.data['resp.corr'][condN]
#add this RT only if correct ans given
if thisAcc==1 and thisRT<2.0:
RTs[thisCondition].append(thisRT)
name = subj.extraInfo['participant']
print 'analysed %s' %(name)
#now calculate means for each condition and insert into sheet
meanRTs={}
for condition in RTs.keys():
thisMean = mean(RTs[condition])
col=outCols[condition]
xlSheet.cell(col+str(outRow)).value=str(thisMean)
if not anonymous:
xlSheet.cell('A'+str(row)).value = str(name)
outRow=outRow+1#goto next row for next subject
# except:
# print 'problem with', fileName
xlsxWriter.save(filename = outputFilename)