当前位置: 首页 > news >正文

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

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

相关文章:

  • PXE结合kiskstart实现自动化安装系统
  • dm6446开发大全资料号称宇宙最全
  • java空指针注意事项
  • linux下个人权限的Apache服务器的php的yii搭建
  • atitit. 日志系统的原则and设计and最佳实践(1)-----原理理论总结.
  • C语言中迭代器的设计与使用
  • 利用ACL库快速创建你的网络程序--ACL_VSTREAM 流的使用
  • 架构反思案例之“分布式”的架构案例
  • HttpClient---------demo
  • SQLSERVER存储过程基本语法
  • 安装redis
  • C#实现一个最简单的HTTP服务器
  • 【特别推荐】14个支持响应式设计的流行前端开发框架
  • 2012毕业找工作记录点滴
  • FAQ_Zabbix:解决模板收集到的数据和真实数据有偏差
  • Google 是如何开发 Web 框架的
  • 自己简单写的 事件订阅机制
  • 【108天】Java——《Head First Java》笔记(第1-4章)
  • Android单元测试 - 几个重要问题
  • axios 和 cookie 的那些事
  • canvas 五子棋游戏
  • leetcode讲解--894. All Possible Full Binary Trees
  • mockjs让前端开发独立于后端
  • Redis的resp协议
  • sessionStorage和localStorage
  • Spark RDD学习: aggregate函数
  • SpiderData 2019年2月13日 DApp数据排行榜
  • Yeoman_Bower_Grunt
  • 安卓应用性能调试和优化经验分享
  • 半理解系列--Promise的进化史
  • 成为一名优秀的Developer的书单
  • 如何使用 OAuth 2.0 将 LinkedIn 集成入 iOS 应用
  • 深入 Nginx 之配置篇
  • 手写一个CommonJS打包工具(一)
  • 微信小程序设置上一页数据
  • 转载:[译] 内容加速黑科技趣谈
  • C# - 为值类型重定义相等性
  • ​直流电和交流电有什么区别为什么这个时候又要变成直流电呢?交流转换到直流(整流器)直流变交流(逆变器)​
  • !!Dom4j 学习笔记
  • # 计算机视觉入门
  • # 深度解析 Socket 与 WebSocket:原理、区别与应用
  • #单片机(TB6600驱动42步进电机)
  • #中的引用型是什么意识_Java中四种引用有什么区别以及应用场景
  • (1)(1.9) MSP (version 4.2)
  • (11)MSP430F5529 定时器B
  • (4.10~4.16)
  • (八)光盘的挂载与解挂、挂载CentOS镜像、rpm安装软件详细学习笔记
  • (附源码)springboot“微印象”在线打印预约系统 毕业设计 061642
  • (附源码)springboot太原学院贫困生申请管理系统 毕业设计 101517
  • (一)C语言之入门:使用Visual Studio Community 2022运行hello world
  • ***linux下安装xampp,XAMPP目录结构(阿里云安装xampp)
  • ./configure、make、make install 命令
  • .NET 除了用 Task 之外,如何自己写一个可以 await 的对象?
  • .NET 中 GetProcess 相关方法的性能
  • .NET大文件上传知识整理