Recently, the company had a project that needed to operate Word documents directly in the IE browser, and then searched for some information on the Internet, which was not ideal. However, we finally found a control with strong functions. It is a control developed by foreigners and needs to be registered. Fortunately, when there is no registration, a dialog box pops up when the page is closed. If someone can put it... Thank you very much. Okay. You don't have to talk about it. Let's talk about the recently collected results. Different levels of functions have different levels of corresponding solutions, depending on your needs. Here I will propose three solutions.
1st solutions, original flavor
Office documents such as Word, Excel, and viso can be converted in Versions later than 2003, such as XML or HTML. Therefore, the simplest solution is to directly useCodeConvert the Word documents to HTML format, so that they can be viewed online, but they cannot be edited.
If an Excel file is converted to an XML format, it can be operated online. For detailed operation instructions, refer to the webexcel file I wrote earlier.
The attachment also adds an example of converting the Word file into HTML format by code. It is for your reference only. It is also from other places and can be used after testing.
2nd solutions and good cooling under big trees
To say this, our 2nd solution is to use Microsoft's stuff. In fact, Microsoft has a lot of good stuff, but it just prefers to sneak out and is rarely known. In other words, he doesn't want to push this product at all. He can only say: this can be done.
Well, we need to use the Microsoft dsoframer control, which is free of charge and has a slightly better function than the 1st solutions. This control has not been studied in detail and looks at others' demos, I don't know if the function is not strong. The Attachment also contains the relevant code. You can refer to it directly.
3rd solutions and different approaches
Since the big tree of Microsoft is unreliable, we can only rely on third-party controls. Foreigners are doing a great job in this direction, and there are all controls or plug-ins available. We can't think of them, but we can't find them... Alas, China...
This control is the officeocxsetup plug-in. The current version is 7. 4. 0. 236. the attachment is installed hereProgramAfter installation, there will be examples of various programming tools. The examples provided by the installer only provide simple operations such as opening, closing, and saving.
Look at the demo provided, it seems that you can operate on office files such as Word, Excel, PPT, and VIOs, which is really powerful!
The following describes a complicated business scenario: a customer's document needs to be input, but other help texts such as labels in the document cannot be modified by the customer, we reserve the places that customers can modify. That is to say, the document provided by word is also equivalent to the ASPX page, and only some controls can be left for users to edit.
At the same time, word also provides some simple controls, such as date and drop-down menu. If you want to assign values to the drop-down menu. Okay. The production process is as follows:
Environment requirements
A) word2007, preferably version 2007, because the control has been added
B) tools that can maintain XSD files (vs2005 or vs2008 is recommended)
Glossary
A) bookmarks
The bookmarks in Word documents are not easy to talk about. It can be understood that an identifier is reserved in the document. You can search for the data by the identifier.
B) node
Word itself supports importing XSD architecture documents. The node function is similar to the bookmarks function. It can be understood as bookmarks, but it is more powerful.
Node operation steps
A) create a Word template file, as shown in-1:
Figure-1
B) After receiving the Word Document, the developer needs to create the XSD document (equivalent to defining the XML file structure, as shown in-2 and figure-3:
Figure 2
Figure-3
Note:
I. XSD provides two methods: Visualization and coding maintenance. I personally suggest using the encoding method for maintenance.
Ii. <Xs: element name = "death report card"> the node is the Report Card Name.
Iii. <Xs: element name = "Xingming"> indicates a node, which is equivalent to a dbcolumnname in dbtable.
Iv. <Xs: attribute name = "dbtablename" is the custom attribute of the node. It is added by ourselves. The current attribute definition is as follows:
Dbtablename |
Name of the DB table to which the node belongs |
Dbcolumnname |
Column name in the DB table to which the node belongs |
Dbcolumndatatype |
Column data types, such as int and varchar |
Dbcolumnedittype |
Column editing type, such as textbox and dropdownlist |
Dbcolumnvalue |
Column value. If the editing type is a drop-down menu, the data value is written to this attribute. |
Helpsign |
Public Help identification, such as ethnic minorities and diseases |
Comments |
Chinese column meaning, which can be used for mandatory items detection. The prompt content is displayed. |
V. You only need to copy the node and modify its custom property value.
C) after writing the XSD document, we need to merge the XSD document into the word, because we use the Node Method to operate the data.
I. Open the Word document and select the development tools page.
Ii. Click the "architecture" menu, and the "template and add-on" dialog box appears, as shown in-4:
Figure 4
Iii. Click "add schema" to introduce the defined XSD file and define an alias for it, as shown in-5:
Figure 5
Iv. After completing the preceding operations, click the "structure" menu shown in-4. The page shown in-6 is displayed. Note: "Only list the child elements of the current element" is not checked.
Figure 6
V. in the interface shown in-6, the subitem contains the "death report card", which is the parent node of all our <Xs: Element> projects and needs to be introduced into it, note that you must select "apply to entire document" when introducing it, as shown in-7:
Figure-7
Vi. Next, we can select the subitem to the cell. Just click it. The operation result is shown in-8:
Figure-8
VII. right-click the node We just added, and choose properties. The page shown in-8 is displayed. This interface is used to add custom attributes to the node, add it to the "allocated attributes" item. In this way, you can use the code method to set values and assign values to custom attributes, as shown in-9:
Figure-9
VIII. Through the above steps, we have completed the setup of the report card. At this point, we can perform operations on the document through encoding, including the node value and value assignment, the node custom attribute value and value assignment. However, if you use it directly, some text may be deleted by mistake. Therefore, you also need to protect the document and set a region that only allows users to edit it.
D) Protect documents and only allow entry. The detailed procedure is as follows.
I. Switch to the development tools page, and click protection document. The page shown in-10 is displayed:
Figure-10
Ii. Select a template that we just edited, select "allow only such edits in the document" on the right, and then select the "everyone" check box.
III. All other nodes can follow this procedure. After the settings are complete, select "Yes, enable force protection" (no password is set ). After this operation, the customer will not accidentally delete the data when it is delivered to the customer, because all the data is protected and the remaining data is editable by the customer.
Iv. After protection, the effect is shown in-11. You can stop expansion. Note: Do not select the "highlight editable areas" check box. It is used to display/hide protected areas.
Figure-11
E) Finally, we need to beautify it, as shown in-12:
Do not select the "show XML mark in document" check box. It is used to show/hide node items.
Figure-12
Set bookmarks
A) set the header as an example.
I. in the header, enter the "hospital name" text, press a few spaces, then select the space, switch to the "insert" Page, select bookmarks, and the page shown in-13 appears, enter a bookmark name and add it to the list box.
Figure 13
Ii. After the settings are complete, as shown in-14, this is the bookmarks we have set for the future. You can set the node protection mode to protect the bookmarks.
Figure 14
Control Installer
A) after installing the control, find the installation path, as shown in-15.
The I. officeviewer. cab file is the cab control package to be loaded by our Asp.net program.
II. The samples folder is an example of each programming tool, which can be run directly. There is an Asp.net example in it. Let's take this as an example:
Figure-15
B) Open the Asp.net page. The cab loading method is also based on its loading method.
I. We can directly copy it when using it, for example, opening a Word document, event registration method, etc.
Ii. Here we will focus on the events that will be frequently operated in the future, that is, double-click the event, because we need to double-click the event to bring up public help and provide the quick entry function, as shown in-16:
Figure 16
C) Code Description
I. Declare two variables: array_xmlnodenameist and array_bookmarknamelist, which are used to store the node name list and bookmarkelist list in Word documents. They are used to improve performance and do not need to be retrieved from each recycle. The preceding variables can be assigned values in the oa1_incluentopened event.
Ii. Data Values and value assignment methods of controls and DB tables-17 and figures-18.
For the III. js method, see the edrawoffice. js file. Some functions have been encapsulated.
Figure-17
Figure-18
Word Control usage
A) after using the self-contained control in word2007 to implement a simple definition of data, the data value and value assignment operations, such as the date and Gender drop-down menu, are shown in-22:
Figure-22
B) when assigning values to data, it is a drop-down menu operation. The displayed value must be displayed in the page control. The data value is stored in the custom attribute of the node. This function has been implemented and the code is in edrawoffice. in Js.
Remarks
1. I want to provide technical support for this control. If you have any questions, please contact me.
2. The evaluation version of this control. A dialog box will pop up when the page is closed, as shown in-23. If you have any experts, I would like to thank you very much.
Figure-23
Code and Installer: Online Web operations on office files. File