做个网络考试系统 如何实现用word预览试卷 正做毕业设计,实现word预览试卷试卷功能,谢谢大家了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //添加试卷头const Number:array[1..10] of string = ('一', '二', '三', '四', '五', '六', '七', '八', '九', '十');procedure SetTitle(var PaperDocument:TWordDocument; var PaperFont:TWordFont; const Title:string);begin // '生物科学与工程学院 人体解剖生理学试卷' PaperDocument.Range.InsertAfter(Title + #13); SetFont(PaperFont, PaperDocument, 1, 0, 0, 24); PaperDocument.Range.InsertAfter('院系___________班级__________姓名_________学号_____得分________' + #13); SetFont(PaperFont, PaperDocument, 1, 0, 0, 16);end;//设置文档字体procedure SetFont(var WordFont:TWordFont; var WordDocument:TWordDocument; aBold, aItalic, aShadow, aSize:integer);begin WordFont.ConnectTo(WordDocument.Sentences.Get_Last.Font); WordFont.Name := '宋体'; WordFont.Bold := aBold; WordFont.Italic := aItalic; WordFont.Shadow := aShadow; WordFont.Size := aSize;end;//创建Word文档procedure CreateWordDocument(var WordApplication:TWordApplication; var WordDocument:TWordDocument);var Docs, Template, NewTemplate, ItemIndex:OleVariant;begin try Template := EmptyParam; NewTemplate := True; ItemIndex := 1; try WordApplication.Connect; except MessageBox(Application.Handle, '您可能没有安装Word!建议您安装WordXP,并选择完全安装!如果还有问题请检查您的系统!', '错误', MB_OK + MB_ICONSTOP); Abort; end; WordApplication.Visible := True; WordApplication.Caption := '电子试卷生成系统'; Template := EmptyParam; NewTemplate := False; Docs := WordApplication.Documents; Docs.Add(NewTemplate := True); WordDocument.ConnectTo(WordApplication.Documents.Item(ItemIndex)); //关闭语法检查和拼写检查 WordApplication.Options.CheckSpellingAsYouType := False; WordApplication.Options.CheckGrammarAsYouType := False; except on E:Exception do begin MessageBox(Application.Handle, PChar(E.Message), '错误', MB_OK + MB_ICONSTOP); WordApplication.Disconnect; end; end;end;procedure InsertTK(var Query:TQuery; var PaperDocument:TWordDocument; var AnDocument:TWordDocument; const HaveAns:Boolean; const SQLStr:string; var S:Integer; var StrList:TStringList);var I:Integer;begin if StrList.Count > 0 then begin if HaveAns then begin Inc(s); PaperDocument.Range.InsertAfter(Number[S] + '. 填空题(每题__分,共__题)' + #13); AnDocument.Range.InsertAfter(Number[S] + '. 填空题(每题__分,共__题)' + #13); end else begin Inc(s); PaperDocument.Range.InsertAfter(Number[S] + '. 填空题(每题__分,共__题)' + #13); end; for i := 1 to StrList.Count do begin Query.Close; Query.SQL.Clear; Query.SQL.Add(SQLStr); Query.ParamByName('ID').AsInteger := StrToInt(StrList.Strings[i - 1]); Query.Open; if Query.RecordCount > 0 then begin if HaveAns then begin PaperDocument.Range.InsertAfter(IntToStr(i) + '. ' + Query.FieldByName('填空题').AsString + #13); AnDocument.Range.InsertAfter(IntToStr(i) + '. ' + Query.FieldByName('填空题').AsString + #13); AnDocument.Range.InsertAfter('正确答案:' + Query.FieldByName('答案').AsString + #13); end else begin PaperDocument.Range.InsertAfter(IntToStr(i) + '. ' + Query.FieldByName('填空题').AsString + #13); end; end; end; end;end;这个是我写的电子试卷的代码,你可以参考一下 何必要用word预览用richEdit控件即可 DELPHI中调用带有日期型参数的存储过程 请各位大侠指点! 关于TQuery.SQL.Add以及ParamByName的问题 请推荐经典第三方控件,及下载网址 如何,实现拖拉功能!! 刚被MM甩了,十分郁闷,怎么办? 如何在主线程中终止线程的运行 怎么搞的,是不是我的网速慢,怎么给不了分呀(内空) 请问:如何在不打开一个.txt文件的情况下,将其内容全部复制到剪贴板上。(不限制文本文件大小) 关于语音识别系统的问题。 哪位有针织服装类系统的数据结构,能不能介绍一下 ctrl+alt+del使钩子失效,如何解决
Number:array[1..10] of string = ('一', '二', '三', '四', '五', '六', '七',
'八', '九', '十');procedure SetTitle(var PaperDocument:TWordDocument; var PaperFont:TWordFont;
const Title:string);
begin // '生物科学与工程学院 人体解剖生理学试卷'
PaperDocument.Range.InsertAfter(Title + #13);
SetFont(PaperFont, PaperDocument, 1, 0, 0, 24);
PaperDocument.Range.InsertAfter('院系___________班级__________姓名_________学号_____得分________' + #13);
SetFont(PaperFont, PaperDocument, 1, 0, 0, 16);
end;
//设置文档字体procedure SetFont(var WordFont:TWordFont; var WordDocument:TWordDocument; aBold,
aItalic, aShadow, aSize:integer);
begin
WordFont.ConnectTo(WordDocument.Sentences.Get_Last.Font);
WordFont.Name := '宋体';
WordFont.Bold := aBold;
WordFont.Italic := aItalic;
WordFont.Shadow := aShadow;
WordFont.Size := aSize;
end;
//创建Word文档procedure CreateWordDocument(var WordApplication:TWordApplication; var
WordDocument:TWordDocument);
var
Docs, Template, NewTemplate, ItemIndex:OleVariant;
begin
try
Template := EmptyParam;
NewTemplate := True;
ItemIndex := 1;
try
WordApplication.Connect;
except
MessageBox(Application.Handle,
'您可能没有安装Word!建议您安装WordXP,并选择完全安装!如果还有问题请检查您的系统!',
'错误', MB_OK + MB_ICONSTOP);
Abort;
end;
WordApplication.Visible := True;
WordApplication.Caption := '电子试卷生成系统';
Template := EmptyParam;
NewTemplate := False;
Docs := WordApplication.Documents;
Docs.Add(NewTemplate := True);
WordDocument.ConnectTo(WordApplication.Documents.Item(ItemIndex));
//关闭语法检查和拼写检查
WordApplication.Options.CheckSpellingAsYouType := False;
WordApplication.Options.CheckGrammarAsYouType := False;
except
on E:Exception do
begin
MessageBox(Application.Handle, PChar(E.Message), '错误', MB_OK +
MB_ICONSTOP);
WordApplication.Disconnect;
end;
end;
end;procedure InsertTK(var Query:TQuery; var PaperDocument:TWordDocument; var
AnDocument:TWordDocument;
const HaveAns:Boolean; const SQLStr:string; var S:Integer; var
StrList:TStringList);
var
I:Integer;
begin
if StrList.Count > 0 then
begin
if HaveAns then
begin
Inc(s);
PaperDocument.Range.InsertAfter(Number[S] + '. 填空题(每题__分,共__题)'
+ #13);
AnDocument.Range.InsertAfter(Number[S] + '. 填空题(每题__分,共__题)' +
#13);
end
else
begin
Inc(s);
PaperDocument.Range.InsertAfter(Number[S] + '. 填空题(每题__分,共__题)'
+ #13);
end;
for i := 1 to StrList.Count do
begin
Query.Close;
Query.SQL.Clear;
Query.SQL.Add(SQLStr);
Query.ParamByName('ID').AsInteger := StrToInt(StrList.Strings[i - 1]);
Query.Open;
if Query.RecordCount > 0 then
begin
if HaveAns then
begin
PaperDocument.Range.InsertAfter(IntToStr(i) + '. ' +
Query.FieldByName('填空题').AsString + #13);
AnDocument.Range.InsertAfter(IntToStr(i) + '. ' +
Query.FieldByName('填空题').AsString + #13);
AnDocument.Range.InsertAfter('正确答案:' +
Query.FieldByName('答案').AsString + #13);
end
else
begin
PaperDocument.Range.InsertAfter(IntToStr(i) + '. ' +
Query.FieldByName('填空题').AsString + #13);
end;
end;
end;
end;
end;这个是我写的电子试卷的代码,你可以参考一下
用richEdit控件即可