VC生成word文档的部分代码的记录.doc

上传人:仙人指路1688 文档编号:2385746 上传时间:2023-02-17 格式:DOC 页数:5 大小:24.50KB
返回 下载 相关 举报
VC生成word文档的部分代码的记录.doc_第1页
第1页 / 共5页
VC生成word文档的部分代码的记录.doc_第2页
第2页 / 共5页
VC生成word文档的部分代码的记录.doc_第3页
第3页 / 共5页
VC生成word文档的部分代码的记录.doc_第4页
第4页 / 共5页
VC生成word文档的部分代码的记录.doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《VC生成word文档的部分代码的记录.doc》由会员分享,可在线阅读,更多相关《VC生成word文档的部分代码的记录.doc(5页珍藏版)》请在三一办公上搜索。

1、protected:/变量 _Application wordApp; Documents wordDocs; _Document wordDoc; Selection wordSelection; Range wordRange; Tables wordTables; Table wordTable; Cell wordCell; Cells wordCells; _Font wordFont; void CAUTOYAOCE:OnCreateReport() / CurrentCount MotherVoltageCount CommonVoltageCount PowerCount Po

2、werFactorCount FrequencyCount / TODO:初始化WORD :CoInitialize(NULL); /初始化COM组件(必须添加,否则无法启动WORD)调用完毕后 CoUninitialize(); if (!wordApp.CreateDispatch(_T(Word.Application) AfxMessageBox(Word CreateDispatch Failed!); wordApp.SetVisible(TRUE);/make visible wordApp.Activate();/激活 wordDocs=wordApp.GetDocuments

3、();/get documents object / CComVariant tpl(_T(),Visble,DocType(0),NewTemplate(false); wordDoc=wordDocs.Add(&tpl,&NewTemplate,&DocType,&Visble); wordSelection=wordApp.GetSelection(); SYSTEMTIME sysTime; GetLocalTime(&sysTime); CString strReport; strReport.Format( 日期: %d-%d-%d 时间: %d:%d:%d rn rn,sysTi

4、me.wYear,sysTime.wMonth,sysTime.wDay,sysTime.wHour,sysTime.wMinute,sysTime.wSecond); wordSelection.TypeText(strReport); UpdateData(); CString m_PCT; m_PCT.Format(CT变比:%f,m_CT); wordSelection.TypeText(m_PCT+ ); m_PCT.Format(PT变比:%f,m_PT); wordSelection.TypeText(m_PCT+rn); /TODO:在WORD中插入表格 if(CurrentC

5、ount) CreateDoc(遥测电流幅值检验,CurrentBuf,CurrentCount,3); /生成电流报表 if(MotherVoltageCount) CreateDoc(遥测电压母线幅值检验,MotherVoltageBuf,CurrentCount,3); /生成母线电压报表 if(CommonVoltageCount) CreateDoc(遥测电压普线幅值检验,CommonVoltageBuf,CurrentCount,3); /生成普线电压报表 if(PowerCount) CreateDoc(遥测功率测量检验,PowerBuf,CurrentCount,2); /生成

6、功率报表 if(PowerFactorCount) CreateDoc(遥测功率因数测量检验,PowerFactorBuf,CurrentCount,1); /生成功率因数报表 if(FrequencyCount) CreateDoc(遥测频率测量检验,FrequencyBuf,CurrentCount,1); /生成频率报表 /TODO:保存WORD CComVariant FileName,FileFormat(0),LockComments(false),Password(_T(),AddToRecentFiles(true),WritePassword(_T(); CComVarian

7、t ReadOnlyRecommended(false),EmbedTrueTypeFonts(false),SaveNativePictureFormat(false),SaveFormsData(false),SaveAsAOCELetter(false); CComVariant Encoding(false),InsertLineBreaks(false),AllowSubstitutions(false),LineEnding(false),AddBiDiMarks(false); strReport.Format(d:%d年%d月%d日%d时%d分%d秒 报告,sysTime.wY

8、ear,sysTime.wMonth,sysTime.wDay,sysTime.wHour,sysTime.wMinute,sysTime.wSecond); FileName=strReport; /文件名 wordDoc.SaveAs(&FileName,&FileFormat,&LockComments,&Password,&AddToRecentFiles,&WritePassword, &ReadOnlyRecommended,&EmbedTrueTypeFonts,&SaveNativePictureFormat,&SaveFormsData, &SaveAsAOCELetter,

9、 &Encoding,&InsertLineBreaks,&AllowSubstitutions,&LineEnding,&AddBiDiMarks); wordFont.ReleaseDispatch();wordCells.ReleaseDispatch();wordTable.ReleaseDispatch();wordTables.ReleaseDispatch();wordRange.ReleaseDispatch(); wordSelection.ReleaseDispatch();wordDoc.ReleaseDispatch();wordDocs.ReleaseDispatch

10、();wordApp.ReleaseDispatch(); :CoInitialize(NULL); void CAUTOYAOCE:CreateCurrentDoc() wordSelection.TypeText( 遥测电流幅值检验报表rn rn); wordSelection.TypeText( 日期: 2008-*-*时间: *:*rn rn); wordTables=wordDoc.GetTables(); wordRange=wordSelection.GetRange(); CComVariant defaultBehavior(1),AutoFitBehavior(0); wo

11、rdTable=wordTables.Add(wordRange,7,7,&defaultBehavior,&AutoFitBehavior); / UpdateData(); wordCell=wordTable.Cell(1,1); wordCell.Select(); wordSelection.MoveDown(&CComVariant(5),&CComVariant(1),&CComVariant(1); wordCells=wordSelection.GetCells(); wordCells.Merge(); wordCells.SetVerticalAlignment(1);

12、wordSelection.TypeText(二次电流); wordCell=wordTable.Cell(1,2); wordCell.Select(); wordSelection.MoveRight(&CComVariant(1),&CComVariant(2),&CComVariant(1); /合并单元格时要使用&CComVariant(1) wordCells=wordSelection.GetCells(); wordCells.Merge(); wordSelection.TypeText(测控装置显示值); wordCell=wordTable.Cell(1,3); word

13、Cell.Select(); wordSelection.MoveRight(&CComVariant(1),&CComVariant(2),&CComVariant(1); wordCells=wordSelection.GetCells(); wordCells.Merge(); wordSelection.TypeText(操作员工作站显示值); wordSelection.MoveRight(&CComVariant(12),&CComVariant(2),&CComVariant(0); CString temp6=Ia(A),Ib(A),Ic(A),Ia(A),Ib(A),Ic(A

14、); for(int i=0;i6;i+) wordSelection.TypeText(tempi); wordSelection.MoveRight(&CComVariant(12),&CComVariant(1),&CComVariant(0); /单纯右移时使用&CComVariant(12) CString str21=1.0000,x,x,x,x,x,x,5.0000,xx,xx,xx,xx,xx,xx,基本误差,xxx,xxx,xxx,xxx,xxx,xxx; for(i=0;i21;i+) wordSelection.TypeText(stri); wordSelection.

15、MoveRight(&CComVariant(12),&CComVariant(1),&CComVariant(0); wordSelection.TypeText(结论); wordCell=wordTable.Cell(6,2); wordCell.Select(); wordSelection.MoveRight(&CComVariant(1),&CComVariant(5),&CComVariant(1); wordCells=wordSelection.GetCells(); wordCells.Merge(); wordSelection.TypeText(合格); wordSel

16、ection.MoveRight(&CComVariant(12),&CComVariant(1),&CComVariant(0); wordSelection.TypeText(备注); wordCell=wordTable.Cell(7,2); wordCell.Select(); wordSelection.MoveRight(&CComVariant(1),&CComVariant(5),&CComVariant(1); wordCells=wordSelection.GetCells(); wordCells.Merge(); wordSelection.TypeText(基本误差为各测点误差的最大值;基本误差绝对值应小于0.20%); 本文来自CSDN博客,转载请标明出处:file:/E:/资料库/VC开发/word操作/VC生成word文档的部分代码%20-%20qj840828的专栏%20-%20CSDN博客.mht

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号