Select the questions in the question library to dynamically generate the exam (Word format)

Source: Internet
Author: User

 

I believe that companies that are engaged in the education system will have this need. In the end, they still need to generate examination papers for question management. How can they generate examination papers? Of course, HTML can be combined into a test paper on the page, but HTML page layout is the problem, and the printed result is naturally not good; another more important reason is that if the generated exam is in HTML format, saving the complex questions is a problem. For example, the four options for a multiple-choice question are four different pictures, and for example, a complex formula exists in the question. If such questions are saved using database fields, it is indeed a big problem, after all, database fields can only store strings or binary streams.

 

How can I save each question in word? If you save a question in a Word file, no matter whether the formula or image is saved to a file, it must be correct, the problem is, if multiple questions cannot be combined into one word file when the exam is generated, what technology can be used to achieve it? Here, a third-party document middleware product soaoffice is used, which can be used in either of the following methods: applytemplatefromurl and insertdocumentfromurl. The former is designed for the soaoffice, So if you insert a Word file, directly insert the word file to the front of the entire file. The latter is to insert a Word file to the current cursor. Here, the latter insertdocumentfromurl is used to merge the question file and generate the exam.

 

Idea: Give the instructor a question selection interface. After selecting the question to be used, click "generate exam" to open a blank Word file, then, use the corresponding program to generate multiple insertdocumentfromurl commands (that is, JS Code). When the document is opened, the insertdocumentfromurl method is automatically called, insert the questions selected by the instructor to the blank Word file one by one to generate a test paper.

Method: function insertdocumentfromurl (docurl );

Function: insert the word file of the specified URL to the current cursor.

Description: docurl: Specifies the URL location of the Word file relative to the current page, which is of the string type.
If the first character of the docurl parameter is "/", no matter what the current page path is, the relative path is the Web root path http: // yourwebsite.

 

Details 1: In this demo, not a blank Word file is opened, there is a title "Middle School midterm exam questions" and "1. When a word opens a file, the cursor is located at the beginning of the entire file by default. Therefore, you need to move the cursor to the end of the file, use the Office VBA interface called by JS (soaoffice supports js to call VBA interface, which is why soaoffice is used) to position the cursor at the end of the document:

Document. getelementbyid ('soaofficectrl'). Document. application. selection. endkey (6 );

 

Details 2: Add a number for each question before inserting a question, or use the office VBA interface function called by soaoffice Js. pnum is to save the question number:

Document. getelementbyid ('soaofficectrl'). Document. application. selection. range. Text = '"+ String. valueof (pnum) + ".';

 

Details 3: This demo saves each question file (in DOC format) to the database field. You can open demo/DemoData/soademo. MDB file, two fields in the stream table: ID and word. The long binary data stored in the word field is the question file. When you use soaoffice to open and edit each question file, you can use the openfile. jsp page to read the file stream of the specified file input. For details, see soactrl. webopen ("openfile. jsp? Id = "+ Sid, 2," somebody "," word. Document ");

When saving the file, use SaveFile. jsp to save the file to the database field. For details, see soactrl. savedocurl = "SaveFile. jsp? Id = "+ Sid;

 

Details not done: If the doctext attribute of soaoffice is used to obtain the text of the question while editing the question, it is also saved to the text field of the database, in this way, you can search the full text of the questions, or preview the questions. If anyone is interested, refer to the "preview" link.

 

Download this demo code: http://ishare.iask.sina.com.cn/f/10669215.html

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.