StarkSoft题库管理系统(二)--生成word格式试卷
一、功能介紹
? ? 1、自定義試題庫(kù)管理系統(tǒng)目錄、難易程度,題型,知識(shí)庫(kù)等。
? ? 2、試題錄入。
? ? 3、強(qiáng)大的試題編輯功能,并與通常應(yīng)用編輯工具有共通。
? ? 4、靈活的試卷構(gòu)造功能,用戶可自定義試卷標(biāo)題、試題分類,試題數(shù)量、總分、試題難度系數(shù)等。
? ? 5、人工生成試卷和自動(dòng)生成試卷文檔格式標(biāo)準(zhǔn)通用。能夠合理使用,有效再編輯,保存,方便瀏覽和打印輸出。
? ? 6、題庫(kù)管理,可以隨時(shí)分散和集中管理題庫(kù)數(shù)據(jù)。
二、菜單功能
? ? 1、基礎(chǔ)數(shù)據(jù)維護(hù):試題分類設(shè)置;題型設(shè)置;難易程度;知識(shí)點(diǎn)庫(kù)設(shè)置
? ? 2、題庫(kù)管理:試題錄入
? ? 3、試卷管理:人工生成試卷;自動(dòng)生成試卷;試卷庫(kù)管理
導(dǎo)出試卷到WORD
#region 創(chuàng)建word試卷(直接導(dǎo)出為word)/// <summary>/// 創(chuàng)建word試卷/// </summary>/// <param name="PathName"></param>public void CreateWordFile(string PathName){try{Object Nothing = System.Reflection.Missing.Value;object filename = PathName; //文件保存路徑//1.創(chuàng)建Word文檔Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();Microsoft.Office.Interop.Word.Document WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);//2.添加頁(yè)眉WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView;WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader;WordApp.ActiveWindow.ActivePane.Selection.InsertAfter("[入職考試試卷]");WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;//設(shè)置右對(duì)齊WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument;//跳出頁(yè)眉設(shè)置WordApp.Selection.ParagraphFormat.LineSpacing = 8f;//設(shè)置文檔的行間距//3.移動(dòng)焦點(diǎn)并換行object count = 14;object WdLine = Microsoft.Office.Interop.Word.WdUnits.wdLine;//換一行;WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移動(dòng)焦點(diǎn)WordApp.Selection.TypeParagraph();//插入段落#region 標(biāo)題WordApp.Selection.Font.Size = 20;WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; // 居中WordApp.Selection.Font.Bold = 1; // 黑體WordApp.Selection.TypeText("xxxx入職考試");WordApp.Selection.TypeParagraph();//WordApp.Selection.TypeParagraph();#endregion//設(shè)置內(nèi)容部分格式WordApp.Selection.Font.Size = 12;WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft; // 居中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++ ){//寫(xiě)標(biāo)題WordApp.Selection.TypeText((i+1)+"、"+dt.Rows[i]["name"].ToString()+"(每題3分)" + "\n\n"); int txid = Convert.ToInt32(dt.Rows[i]["id"]);//題型IDDataRow[] 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);//獲取題目?jī)?nèi)容byte[] bWrite = (byte[])dtst.Rows[0]["contents"];//從數(shù)據(jù)庫(kù)中讀出數(shù)據(jù)string s = System.Text.Encoding.UTF8.GetString(bWrite, 0, bWrite.Length);//開(kāi)始寫(xiě)內(nèi)容 WordApp.Selection.TypeText(s);}}WordDoc.Paragraphs.Last.Range.Text = "文檔創(chuàng)建時(shí)間:" + DateTime.Now.ToString();//“落款”WordDoc.Paragraphs.Last.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;//文件保存WordDoc.SaveAs(ref filename, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing); MessageBoxEx.Show("導(dǎo)出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);}catch (Exception ex){MessageBoxEx.Show("導(dǎo)出失敗!" + "\n" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);}}#endregion附完整源代碼下載:http://www.51aspx.com/Code/StarkSoftExam
轉(zhuǎn)載于:https://www.cnblogs.com/starksoft/p/3940361.html
總結(jié)
以上是生活随笔為你收集整理的StarkSoft题库管理系统(二)--生成word格式试卷的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: RBD和AOF持久化对比
- 下一篇: GDB分析PHP连接Memcached