Created
January 7, 2019 02:27
-
-
Save xuqiang1015/ceec5fd9fe885a8d54256097ac4a6b36 to your computer and use it in GitHub Desktop.
This file contains 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 flask import Flask | |
from flask import request | |
from win32com.client import Dispatch | |
import win32com.client | |
import pythoncom | |
app = Flask(__name__) | |
@app.route("/", methods = ['GET', 'POST']) | |
def hello_world(): | |
return "Hello World!" | |
@app.route("/DocText/", methods=['GET', 'POST']) | |
def DocText(): | |
fileName = request.args.get("file") | |
text = ReadDocText(fileName) | |
return text | |
def ReadDocText(fileName): | |
pythoncom.CoInitialize() | |
wordApp = win32com.client.Dispatch("Word.Application") | |
doc = wordApp.Documents.Open(fileName) | |
text = "" | |
if doc: | |
for para in doc.paragraphs: | |
text += para.Range() | |
doc.Close(SaveChanges=0) | |
del wordApp | |
return text | |
if __name__ == '__main__': | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment