欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 运维知识 > windows >内容正文

windows

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

发布时间:2025/3/15 windows 52 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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格式试卷的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。