Word document data upload and read

开发工具与关键技术:vs2015  MVC
作者:陈星宇
撰写时间:2019.6.1

We want to prepare the DOM element in a container for placing a Word document upload form, submit that we need the help of the form of property form submit, submit data to the controller. Which is written as in FIG.
Here Insert Picture Description
First you want to place a div in the outer layer, set the property display: 1none to hide, because it does not need to appear on the page, and then there is the form tag we need to submit the address we need to submit the action, method and type of data submitted, Id give him a form to this, the last means of file input tag attributes, we need to get the word document to upload, which gave force a change event, but when uploading data to trigger change event, submit the file.
Let's trigger input tag by clicking on the Button, to get word document we need.
Here Insert Picture Description
Then triggered uploadWord () change event, then jquery.form plug-in ajaxSubmit () method to submit the form. Address submitted has been set in the action form the form.
Here Insert Picture Description
Parametric methods have received particular about file types are generally used HttpPostedFileBase as the data type, and the parameters to be passed in the past and the Name value input labels are the same, the method can receive up to the data submitted.
Here Insert Picture Description
Since different browsers, file transfer last name is different, we have to consider compatibility issues with browsers, we want to get the same file name.
Here Insert Picture Description
After processing compatible, that is triple the daily document processing operations.
The first step to get the file extension used to determine whether the uploaded file as a Word document, and then name the file.
Here Insert Picture Description
The second step, to determine whether there is a directory, if it will not create.
Here Insert Picture Description
The third step is to save the file path and file
Here Insert Picture Description
While the above steps have been uploaded Word document, but what we need is to read the data inside of HTML has been displayed on the page.
Next we need to change the name, with the extension of the method Replace Word document, replace .html, and then save the file path, the final document will be converted to HTML documents.
Here Insert Picture Description
With the document, and then we use the method IO read out the contents of the document. But there were many tags and attributes, and all we need is a text value, so we need to use a lot of regular circulation and to eliminate many of the tags and attributes, as for the elimination of the code too much, the map does not show all of them.
Here Insert Picture Description
Finally then be extracted by the method of circulating the string with, if necessary wrap, and then stitching br / label wrap
the finished spliced data back page.
Here Insert Picture Description
ID acquisition by the container to be added, the method of the character string displayed html.
Here Insert Picture Description
Such a Word file upload and read is complete.

Guess you like

Origin blog.csdn.net/tianxiu11/article/details/90757775