Skip to content

Instantly share code, notes, and snippets.

@xuqiang1015
Created January 7, 2019 08:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xuqiang1015/ce04e67a239ff27273527e5b7c30774f to your computer and use it in GitHub Desktop.
Save xuqiang1015/ce04e67a239ff27273527e5b7c30774f to your computer and use it in GitHub Desktop.
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