Created
January 7, 2019 08:20
-
-
Save xuqiang1015/ce04e67a239ff27273527e5b7c30774f 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
import sys | |
sys.coinit_flags = 0 | |
from flask import Flask | |
from flask import request | |
from win32com.client import Dispatch | |
import win32com.client | |
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): | |
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