Starksoft Question Bank Management System (2) -- generate a word exam

Source: Internet
Author: User

Export exam to word

# Region create a word exam (export to word directly) /// <summary> /// create a word exam /// </Summary> /// <Param name = "pathname"> </param> Public void createwordfile (string pathname) {try {object nothing = system. reflection. missing. value; object filename = pathname; // file storage path // 1. create a Word document Microsoft. office. interOP. word. application wordapp = new Microsoft. office. interOP. word. applicationclass (); Microsoft. office. interOP. word. documen T worddoc = wordapp. documents. add (ref nothing, ref nothing); // 2. add the header wordapp. activewindow. view. type = wdviewtype. wdoutlineview; wordapp. activewindow. view. seekview = wdseekview. wdseekprimaryheader; wordapp. activewindow. activepane. selection. insertafter ("[entry exam]"); wordapp. selection. paragraphformat. alignment = Microsoft. office. interOP. word. wdparagraphalignment. wdalignparag Raphright; // set the right-aligned wordapp. activewindow. view. seekview = wdseekview. wdseekmaindocument; // jump out of the header and set wordapp. selection. paragraphformat. linespacing = 8f; // set the line spacing of the document // 3. move the focus and wrap the line Object COUNT = 14; object wdline = Microsoft. office. interOP. word. wdunits. wdline; // change the line; wordapp. selection. movedown (ref wdline, ref count, ref nothing); // move the focus wordapp. selection. typeparagraph (); // insert a paragraph # region title wordapp. selection. font. Size = 20; wordapp. selection. paragraphformat. alignment = Microsoft. office. interOP. word. wdparagraphalignment. wdalignparagraphcenter; // center wordapp. selection. font. bold = 1; // wordapp. selection. typetext ("Changcheng information entry examination"); wordapp. selection. typeparagraph (); // wordapp. selection. typeparagraph (); # endregion // set the wordapp content format. selection. font. size = 12; wordapp. selection. paragraphformat. alignment = Microsoft. Office. interOP. word. wdparagraphalignment. wdalignparagraphleft; // center wordapp. selection. font. bold = 0; // string SQL = @ "select * From base_tx"; datatable dt = databaseaccess. getdatatable (SQL); For (INT I = 0; I <DT. rows. count; I ++) {// write the title wordapp. selection. typetext (I + 1) + "," + dt. rows [I] ["name"]. tostring () + "(3 points per question)" + "\ n"); int txid = convert. toint32 (DT. rows [I] ["ID"]); // question type ID datarow [] rows = Dtxz. select ("xztxid =" + txid, "xztxid ASC"); datatable dttemp = dtxz. clone (); dttemp. clear (); foreach (datarow DR2 in rows) {dttemp. rows. add (dr2.itemarray) ;}for (int K = 0; k <dttemp. rows. count; k ++) {string sqlstr = @ "select * From base_st where id =" + dttemp. rows [k] ["xzstid"] + ""; datatable dtst = databaseaccess. getdatatable (sqlstr); // obtain the topic content byte [] bwrite = (byte []) dtst. rows [0] ["Contents "]; // Read data from the database string S = system. text. encoding. utf8.getstring (bwrite, 0, bwrite. length); // start to write the wordapp content. selection. typetext (s) ;}} worddoc. paragraphs. last. range. TEXT = "document creation time:" + datetime. now. tostring (); // "paid" worddoc. paragraphs. last. alignment = Microsoft. office. interOP. word. wdparagraphalignment. wdalignparagraphright; // Save the worddoc file. saveas (ref filename, ref nothing, ref Nothing, ref nothing, ref nothing); messageboxex. show ("exported successfully! "," Prompt ", messageboxbuttons. OK, messageboxicon. Information);} catch (exception ex) {messageboxex. Show (" Export failed! "+" \ N "+ ex. message," prompt ", messageboxbuttons. OK, messageboxicon. Error) ;}# endregion

Complete source code download: http://www.51aspx.com/Code/StarkSoftExam

Starksoft Question Bank Management System (2) -- generate a word exam

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.