Last active
August 29, 2015 14:26
-
-
Save SeongUgJung/eb1643beafc5c087649c to your computer and use it in GitHub Desktop.
Python xlsx 처리 방법
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from openpyxl import Workbook, load_workbook | |
# https://docs.djangoproject.com/en/1.8/topics/http/file-uploads/ | |
# https://docs.djangoproject.com/en/1.8/ref/files/uploads/ | |
# or Custom File Upload Handler | |
# File Upload to Temporary or Memory | |
def xlrd(request): | |
# After Uploaded.... | |
# if xlsx | |
wb = load_workbook(filename='/Users/jsuch2362/PycharmProjects/xlrd/empty_book.xlsx') | |
sheets = wb.get_sheet_names() | |
first_sheet = wb[sheets[0]] | |
return HttpResponse(first_sheet['D18'].value) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# xlsx Write and File Stream | |
from django.http import HttpResponse | |
from openpyxl import Workbook, load_workbook | |
from openpyxl.utils import get_column_letter | |
from openpyxl.writer.excel import save_virtual_workbook | |
def xlxs(request): | |
wb = Workbook() | |
ws1 = wb.active | |
ws1.title = "range names" | |
for row in range(1, 40): | |
ws1.append(range(600)) | |
ws2 = wb.create_sheet(title="Pi") | |
ws2['F5'] = 3.14 | |
ws3 = wb.create_sheet(title="Data") | |
for row in range(10, 20): | |
for col in range(27, 54): | |
_ = ws3.cell(column=col, row=row, value="%s" % get_column_letter(col)) | |
return HttpResponse(save_virtual_workbook(wb), content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment