excel





불러오기


import pandas as pd
import xlsxwriter

output = io.BytesIO()
writer = pd.ExcelWriter(output, engine='xlsxwriter')

getFilePath = os.path.join(settings.DATAS_DIR, 'zztest/panda.xlsx')
getFileName = os.path.basename(getFilePath)
data = pd.read_excel(getFilePath)
data.to_excel(writer, sheet_name='download', index=False)
writer.save()
new_zip.writestr( getFileName, output.getvalue() )


새롭게 생성하기


excel_file = io.BytesIO()
workbook = xlsxwriter.Workbook(excel_file)
worksheet = workbook.add_worksheet()
# Code to populate the workbook
# Get some data to write to the spreadsheet.
data = [["nest", 'home', 'nest'],
        [4, 30, 6],
        [7, 8, 50]]

# Write some test data.
for row_num, columns in enumerate(data):
    for col_num, cell_data in enumerate(columns):
        worksheet.write(row_num, col_num, cell_data)

# Here comes the magic
workbook.close()
excel_file.seek(0)
new_zip.writestr( 'zip.xlsx', excel_file.getvalue() )