摘要: 使用msword.olb规范WORD文件字体,行间距,页边距.
_Application oWordApp; Documents oWordDocs; _Document oWordDoc; Selection oWordSel; _ParagraphFormat oWordParFor; _Font oWordFont; PageSetup oWordPage; Styles oWordStyles; CString strDoc = _T("C:\\正文.doc"); COleVariant vTrue((short)TRUE),vFalse((short)FALSE),vOpt((long)DISP_E_PARAMNOTFOUND,VT_ERROR); if (!oWordApp.CreateDispatch(_T("Word.Application"))) { AfxMessageBox(_T("Word CreateDispatch Failed!")); return ; } try { oWordApp.SetVisible(TRUE); oWordApp.Activate(); oWordDocs = oWordApp.GetDocuments(); oWordDoc = oWordDocs.Open(COleVariant(strDoc),vFalse,vFalse,vFalse,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt); oWordSel = oWordApp.GetSelection(); oWordSel.WholeStory(); oWordFont = oWordSel.GetFont(); oWordFont.SetSize(16.0f); oWordFont = oWordSel.GetFont(); oWordFont.SetName(_T("仿宋_GB2312")); oWordDoc.Save(); oWordParFor = oWordSel.GetParagraphFormat(); oWordParFor.SetRightIndent(0.0f); oWordParFor.SetSpaceBefore(0.0f); oWordParFor.SetSpaceBeforeAuto(0l); oWordParFor.SetSpaceAfter(0.0f); oWordParFor.SetSpaceAfterAuto(0l); oWordParFor.SetLineSpacingRule(4l); oWordParFor.SetLineSpacing(28.0f); oWordParFor.SetAlignment(3l); oWordParFor.SetWidowControl(0l); oWordParFor.SetKeepWithNext(0l); oWordParFor.SetKeepTogether(0l); oWordParFor.SetPageBreakBefore(0l); oWordParFor.SetNoLineNumber(0l); oWordParFor.SetHyphenation(-1l); oWordParFor.SetFirstLineIndent(9.92126f); oWordParFor.SetOutlineLevel(10l); oWordParFor.SetCharacterUnitRightIndent(0.0f); oWordParFor.SetCharacterUnitLeftIndent(0.0f); oWordParFor.SetCharacterUnitFirstLineIndent(2.0f); oWordParFor.SetLineUnitBefore(0.0f); oWordParFor.SetLineUnitAfter(0.0f); oWordParFor.SetAutoAdjustRightIndent(-1l); oWordParFor.SetDisableLineHeightGrid(0l); oWordParFor.SetFarEastLineBreakControl(-1l); oWordParFor.SetWordWrap(-1l); oWordParFor.SetHangingPunctuation(-1l); oWordParFor.SetHalfWidthPunctuationOnTopOfLine(0l); oWordParFor.SetAddSpaceBetweenFarEastAndAlpha(-1l); oWordParFor.SetAddSpaceBetweenFarEastAndDigit(-1l); oWordParFor.SetBaseLineAlignment(4l); oWordDoc.Save(); oWordFont = oWordSel.GetFont(); if (oWordFont.GetNameFarEast() == oWordFont.GetNameAscii()) { oWordFont.SetNameAscii(""); } else { oWordFont.SetNameFarEast(""); } oWordDoc.Save(); oWordPage = oWordDoc.GetPageSetup(); oWordPage.SetOrientation(0l); oWordPage.SetTopMargin(104.8819f); oWordPage.SetBottomMargin(99.2126f); oWordPage.SetLeftMargin(79.37008f); oWordPage.SetRightMargin(73.70078f); oWordPage.SetGutter(0.0f); oWordPage.SetHeaderDistance(42.51968f); oWordPage.SetFooterDistance(49.6063f); oWordPage.SetPageWidth(595.2756f); oWordPage.SetPageHeight(841.8898f); oWordPage.SetFirstPageTray(0l); oWordPage.SetOtherPagesTray(0l); oWordPage.SetSectionStart(2l); oWordPage.SetOddAndEvenPagesHeaderFooter(0l); oWordPage.SetDifferentFirstPageHeaderFooter(0l); oWordPage.SetVerticalAlignment(0l); oWordPage.SetSuppressEndnotes(0l); oWordPage.SetMirrorMargins(0l); oWordPage.SetTwoPagesOnOne(0l); oWordPage.SetBookFoldPrinting(0); oWordPage.SetBookFoldPrintingSheets(1l); oWordPage.SetGutterPos(0l); oWordPage.SetLayoutMode(2l); oWordDoc.Save(); oWordPage.ReleaseDispatch(); oWordFont.ReleaseDispatch(); oWordParFor.ReleaseDispatch(); oWordSel.ReleaseDispatch(); oWordDoc.Close(vOpt,vOpt,vOpt); oWordDoc.ReleaseDispatch(); oWordDocs.ReleaseDispatch(); } catch(...){} oWordApp.Quit(vOpt,vOpt,vOpt); oWordApp.ReleaseDispatch();
时间: 2024-10-08 21:16:07