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"]);//題型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);

                        //獲取題目內容
                        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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM