Created
October 16, 2019 02:14
-
-
Save lmatt-bit/53227c629f341f1f629268ca276b674a to your computer and use it in GitHub Desktop.
pywin32 office
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
| import os | |
| import tempfile | |
| from bottle import route, request, static_file, run | |
| import win32com | |
| from win32com.client import * | |
| word = win32com.client.Dispatch("Word.Application") | |
| word.visible = 1 | |
| @route('/convert', method='POST') | |
| def convert(): | |
| data = request.files.get('data') | |
| name, ext = os.path.splitext(data.filename) | |
| fd, temp_filename = tempfile.mkstemp(suffix=ext, dir="./tmp") | |
| os.close(fd) | |
| data.save(temp_filename, overwrite=True) | |
| doc = word.Documents.Open(temp_filename, ReadOnly=True) | |
| #doc.SaveAs2(temp_filename + ".docx", 16) | |
| #word.ActiveDocument.Close() | |
| doc.Convert() | |
| doc.Close() | |
| return "good" | |
| @route('/test') | |
| def test(): | |
| return static_file("test.html", "./") | |
| run(host="127.0.0.1", port=12345) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment