StarkSoft题库管理系统(二)--生成word格式试卷
生活随笔
收集整理的這篇文章主要介紹了
StarkSoft题库管理系统(二)--生成word格式试卷
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、功能介紹
? ? 1、自定義試題庫管理系統目錄、難易程度,題型,知識庫等。
? ? 2、試題錄入。
? ? 3、強大的試題編輯功能,并與通常應用編輯工具有共通。
? ? 4、靈活的試卷構造功能,用戶可自定義試卷標題、試題分類,試題數量、總分、試題難度系數等。
? ? 5、人工生成試卷和自動生成試卷文檔格式標準通用。能夠合理使用,有效再編輯,保存,方便瀏覽和打印輸出。
? ? 6、題庫管理,可以隨時分散和集中管理題庫數據。
二、菜單功能
? ? 1、基礎數據維護:試題分類設置;題型設置;難易程度;知識點庫設置
? ? 2、題庫管理:試題錄入
? ? 3、試卷管理:人工生成試卷;自動生成試卷;試卷庫管理
導出試卷到WORD
#region 創建word試卷(直接導出為word)/// <summary>/// 創建word試卷/// </summary>/// <param name="PathName"></param>public void CreateWordFile(string PathName){try{Object Nothing = System.Reflection.Missing.Value;object filename = PathName; //文件保存路徑//1.創建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.添加頁眉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;//設置右對齊WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument;//跳出頁眉設置WordApp.Selection.ParagraphFormat.LineSpacing = 8f;//設置文檔的行間距//3.移動焦點并換行object count = 14;object WdLine = Microsoft.Office.Interop.Word.WdUnits.wdLine;//換一行;WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移動焦點WordApp.Selection.TypeParagraph();//插入段落#region 標題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//設置內容部分格式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++ ){//寫標題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);//獲取題目內容byte[] bWrite = (byte[])dtst.Rows[0]["contents"];//從數據庫中讀出數據string s = System.Text.Encoding.UTF8.GetString(bWrite, 0, bWrite.Length);//開始寫內容 WordApp.Selection.TypeText(s);}}WordDoc.Paragraphs.Last.Range.Text = "文檔創建時間:" + 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("導出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);}catch (Exception ex){MessageBoxEx.Show("導出失敗!" + "\n" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);}}#endregion附完整源代碼下載:http://www.51aspx.com/Code/StarkSoftExam
轉載于:https://www.cnblogs.com/starksoft/p/3940361.html
總結
以上是生活随笔為你收集整理的StarkSoft题库管理系统(二)--生成word格式试卷的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: RBD和AOF持久化对比
- 下一篇: 如何删除Mac系统里面的所有 DS_St