StarkSoft题库管理系统(二)--生成word格式试卷

本文介绍了一套自定义试题库管理系统,包括试题录入、编辑、试卷构造及Word格式导出功能。系统支持自定义题库、题型、难易程度和知识点,能灵活生成人工或自动生成的试卷,且导出为Word文档,便于后续编辑、打印。通过SQL查询获取试题信息,实现高效试题管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、功能介绍
    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

转载于:https://www.cnblogs.com/starksoft/p/3940361.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值