VC生成word文档的部分代码的记录_第1页
VC生成word文档的部分代码的记录_第2页
VC生成word文档的部分代码的记录_第3页
VC生成word文档的部分代码的记录_第4页
VC生成word文档的部分代码的记录_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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 PowerFactorCount 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();/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,sysTime.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(CurrentCount) CreateDoc(遥测电流幅值检验,CurrentBuf,CurrentCount,3); /生成电流报表 if(MotherVoltageCount) CreateDoc(遥测电压母线幅值检验,MotherVoltageBuf,CurrentCount,3); /生成母线电压报表 if(CommonVoltageCount) CreateDoc(遥测电压普线幅值检验,CommonVoltageBuf,CurrentCount,3); /生成普线电压报表 if(PowerCount) CreateDoc(遥测功率测量检验,PowerBuf,CurrentCount,2); /生成功率报表 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(); CComVariant 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.wYear,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, &Encoding,&InsertLineBreaks,&AllowSubstitutions,&LineEnding,&AddBiDiMarks); wordFont.ReleaseDispatch();wordCells.ReleaseDispatch();wordTable.ReleaseDispatch();wordTables.ReleaseDispatch();wordRange.ReleaseDispatch(); wordSelection.ReleaseDispatch();wordDoc.ReleaseDispatch();wordDocs.ReleaseDispatch();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); wordTable=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); 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); wordCell.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); 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.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(合格); wordSelection.MoveRight(&CComVariant(12),&CComVariant(1),&CComVariant(0); wordSelection.TypeText(备注); wordCell=wordTable.Cell(7,2); wordCell.Select(); wordSelection.MoveRight(&CComVar

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论