关于VC如何操作word2003
下面是从CSDN上摘抄过来的,主要是今天调试VC操作Word2003的时候,网上下载的是操作Word 2000,但是参数已经有一些不同了。
下面的代码可以在2003中运行,记录在这里便于以后复习用。
感谢您使用微软产品。
对于您所提的问题,确实可以使用OLE Automation在VC++中对Word Object Model进行操作。
下面这篇知识库文章中给出了如何在VC_++中引入Office TypeLib,并通过程序启动MS Excel.参照这篇文章可以使您建立起程序的框架Q178749 HOWTO: Create Automation Project Using MFC and a Type Libraryhttp://support.microsoft.com/support/kb/articles/q178/7/49.asp以下两篇知识库文章给出了具体的样例,如何操作Word和Excel. 您可以使用其中的方法来完成你自己的操作。
具体的对象模型的操作,您需要参见对应产品的VBA帮助文档。
Q178784 HOWTO: Use Automation to Open and Print a Word Documenthttp://support.microsoft.com/support/kb/articles/q178/7/84.aspQ179706 HOWTO: Use MFC to Automate Excel and Create/Format a New Workboohttp://support.microsoft.com/support/kb/articles/q179/7/06.asp这两篇是介绍一些基础的知识以及Office 产品在Automation 上的一些支持以及常见问题。
您可以用作参考。
Q238972 INFO: Using Visual C++ to Automate Officehttp://support.microsoft.com/support/kb/articles/q238/9/72.aspQ196776 FAQ: Office Automation Using Visual C++http://support.microsoft.com/support/kb/articles/q196/7/76.asp此外,我在以下列出了Q178784中的样例代码,并添加了一些中文注释。
Steps to Create the Project---------------------------1. In Microsoft Word, create a new document, add some text to the document, and save it as Test.doc. Close the document and exit Word.2. Follow steps 1 through 12 in the following Microsoft Knowledge Base article to create a sample project that uses the IDispatch interfaces and member functions defined in the MSWord8.olb type library: Q178749 HOWTO: Create an Automation Project Using MFC and a Type Library请先按照Q178749的步骤建立一个框架程序,并引入Word typelib.3. At the top of the AutoProjectDlg.cpp, add the following line: #include "msword8.h" // msword9.h for Word 2000, msword.h for Word 20024. Add the following code to CAutoProjectDlg::OnRun() in the AutoProjectDLG.cpp file.当以上步骤完成后,你会看到项目中有很多新的类,那些类就对应着Word的对象模型。
Sample Code----------- _Application objWord; //定义Word应用程序对象(Word.application) // Convenient values declared as ColeVariants. COleVariant covTrue((short)TRUE), covFalse((short)FALSE), covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);// Get the IDispatch pointer and attach it to the objWord object. if (!objWord.CreateDispatch("Word.Application")) { AfxMessageBox("Couldn't get Word object."); return; } objWord.SetVisible(TRUE); //This shows the application. Documents docs(objWord.GetDocuments());//定义Word Documents对象(Word.Documents) _Document testDoc; //定义Word Document对象(Word.Document) testDoc.AttachDispatch(docs.Open( //可看成VB语句set testDoc = Word.documents.Open(…) COleVariant("C:\\Test.doc",VT_BSTR), covFalse, // Confirm Conversion. covFalse, // ReadOnly. covFalse, // AddToRecentFiles. covOptional, // PasswordDocument. covOptional, // PasswordTemplate. covFalse, // Revert. covOptional, // WritePasswordDocument. covOptional, // WritePasswordTemplate. covOptional) // Format. // Last argument for Word 97 covOptional, // Encoding // New for Word 2000/2002 covTrue, // Visible covOptional, // OpenConflictDocument covOptional, // OpenAndRepair (long)0, // DocumentDirection wdDocumentDirection LeftToRight covOptional // NoEncodingDialog ) // Close Open parameters ); // Close AttachDispatch(?) AfxMessageBox("Now printing 2 copies on the active printer"); testDoc.PrintOut(covFalse, // Background. //可看成VB语句testDoc.PrintOut(…) covOptional, // Append. covOptional, // Range. covOptional, // OutputFileName. covOptional, // From. covOptional, // To. covOptional, // Item. COleVariant((long)2), // Copies. covOptional, // Pages. covOptional, // PageType. covOptional, // PrintToFile. covOptional, // Collate. covOptional, // ActivePrinterMacGX. covOptional // ManualDuplexPrint. covOptional, // PrintZoomColumn New with Word 2002 covOptional, // PrintZoomRow ditto covOptional, // PrintZoomPaperWidth ditto covOptional); // PrintZoomPaperHeight ditto // If you wish to Print Preview the document rather than print it, // you can use the PrintPreview member function instead of the // PrintOut member function: // testDoc.PrintPreview. objWord.Quit(covFalse, // ...
C# 中 打印word文档问题
展开全部 VB中的几种打印方法 1. 采用Visual Basic 提供的简单打印函数PrintForm 方法。
应用程序窗体的PrintForm 方法时,Visual Basic 把窗体的位图送到当前打印机。
该方法的优点在于它几乎不需要任何编程,但也有很大缺陷。
最为突出的是当低分辨率图形在高分辨率打印机上打印时,其结果令人无法满意,会产生锯齿。
下面代码将在打印机上打印窗体。
Private Sub Command1_Click() ' 用PrintForm 打印 Me.PrintForm ' 打印窗体的可见区域 End Sub 2. 用Printer 对象进行高分辨率输出。
但要想产生复杂的打印输出,编程较为烦琐。
Printer 对象代表系统缺省的打印机,Printer 对象支持许多由窗体和图形框所支持的属性和方法,三种对象都有画线和画方框。
应用程序可用以下代码在Printer 对象上画出一平方英寸的方框。
它离左上角二英寸。
注意:打印机以twips 来测量距离。
每英寸有1440 个twips。
Printer.Line(2 *1440,2 *1440) -Step(1440,1440), ,B 打印机、从窗体和图形框都有Circle、PaintPicture、Print、Pset、TextHeight、TextWidth 方法。
使用这些方法,应用程序可以为打印机生成高分辨率输出。
打印文本直接用Print 方法,见下列代码: Printer.Print "Hello,China ComputerWorld!" ' 打印字符串 Printer 对象还有一些窗体和图形框都没有方法: NewPage 告诉打印机,程序对当前输出页的发送已经结束,Printer 对象应开始新的一页。
EndDoc 告诉VB,程序创建文档结束,VB 应将它发送到物理打印机上打印。
KillDoc 取消当前打印作业。
应用程序应该终止由EndDoc 和KillDoc 所设定的每个打印作业。
Zoom 属性用于定义打印输出的缩放因子。
Copies 属性用于定义打印的副本数目。
3. 采用直接将数据传送打印机的方法进行打印输出。
有两种方法将数据送往打印机。
第一种是用Print #方法,就像将数据写入一个文件一样。
另一种方法写端口,但不是送文本,而是送特定的PCL 语言,PCL 表示打印控制语言,它是一种特殊语言,用转义代码来控制打印机的具体动作。
因为此方法太烦琐,本文不做太多介绍。
4. 如果你在编程时用到了RichTextBox 控制,那么你可以使用该控件的SelPrint 方法来打印,使用非常简单。
下面一段代码即用RichTextBox 控件的SelPrint 方法来完成打印。
Private Sub Command3_Click() 'SelPrint 方法CommonDialog1.Flags=cdlPDReturnDC +cdlPDNoPageNums If RTF1.SelLength = 0 Then 'RTF1 为窗体的RichTextBox 控制 CommonDialog1.Flags = CommonDialog1.Flags +cdlPDAllPages Else CommonDialog1.Flags = CommonDialog1.Flags +cdlPDSelection End If CommonDialog1.CancelError = True On Error Resume Next CommonDialog1.ShowPrinter If Err.Number = cdlCancel Then Exit Sub If Err.Number 0 Then Beep MsgBox "Error printing file." &vbCrLf +Err.Description, vbOKOnly +vbExclamation, “Printing Error!" Exit Sub End If Printer.Print "" RTF1.SelPrint CommonDialog1.hDC ' 打印RTF1 控件的可见区域End Sub 上面代码先进行打进设置,再进行打印。
如果不需要设置,采用下面代码更为简单: RTF1.SelPrint Printer.hDC ' 打印RTF1 控件的可见区域 5. 可以在VB 中调用Word 97 提供的OLE 自动化服务,利用Word 97 强大的打印功能来完成VB 打印,笔者认为这是最令人满意的方法。
下面代码说明VB 如何与Word 集成。
Private Sub Command4_Click() ' 调用Word 打印Dim objWord As ObjectConst CLASSOBJECT = "Word.Application"On Error GoTo objErrorSet objWord = CreateObject(CLASSOBJECT)objWord.Visible = TrueobjWord.Documents.AddWith objWord.ActiveDocument.Paragraphs.Last.Range.Bold = False.ActiveDocument.Paragraphs.Last.Range.Font.Size =20.ActiveDocument.Paragraphs.Last.Range.Font.Name ="黑体".ActiveDocument.Paragraphs.Last.Range.Font.ColorIndex==4.ActiveDocument.Paragraphs.Last.Range.Text ="我是计算机世界读者!" End WithClipboard.ClearClipboard.SetText "通过剪切板向WORD 传送数据!" objWord.Selection.Paste objWord.PrintPreview = True ' 预览方式 'objWord.PrintOut' 执行打印 'objWord.Quit' 退出WordExit SubobjError:If Err 429 ThenMsgBox Str $(Err) &Error $Set objWord = Nothing ' 不能创建Word 对象则退出Exit SubElse Resume NextEnd IfEnd Sub 6. 用VC 编制DLL 模块完成打印。
在VB 中调用该模块,用混合编程方法进行打印输出。
因涉及VC 编程比较烦琐,这里不再讨论。
如何将jsp页面转化成word文档打印出来
可以利用table把试卷输出,然后利用JavaScript保存此表格为Word文档。
//下面代码为引用论坛其他人的回复,自己没测试过App为表格ID,你调用一下SaveAs函数. function PrintFile() { var strResult=window.confirm("确认用Word打印吗?"); if(strResult) { try { App.focus(); document.execCommand("SelectAll"); document.execCommand("Copy"); App.focus(); var WordApp=new ActiveXObject("Word.Application"); WordApp.Application.Visible=true; var Doc=WordApp.Documents.Add(); Doc.Activate(); Doc.Content.Paste(); Doc.PrintPreview(); WordApp.DisplayAlerts=false; Doc.Close(); WordApp.DisplayAlerts=true; WordApp.Quit(); } catch(e){} } else { var hwnd=window.open(""); hwnd.document.write(App.innerHTML); } return false; }
origin8.1页面设置问题
ActiveWindow.ActivePane.View.Type = wdOutlineViewActiveWindow.ActivePane.View.Type = wdNormalViewwdMasterView 5 主控视图。
wdNormalView 1 普通视图。
wdOutlineView 2 大纲视图。
wdPrintPreview 4 打印预览视图。
wdPrintView 3 页面视图。
wdReadingView 7 阅读视图。
wdWebView 6 Web 视图。
计算机常用英语单词
展开全部 帮你找了一下 我想应该够全的吧计算机常用英语单词中英文对照查询 [请按CTRL+F键]AActive-matrix主动距陈Adapter cards适配卡Advanced application高级应用Analytical graph分析图表Analyze分析Animations动画Application software 应用软件Arithmetic operations算术运算Audio-output device音频输出设备Access time存取时间access存取accuracy准确性ad network cookies广告网络信息记录软件Add-ons附软件Address地址Agents代理Analog signals模拟信号Applets程序Asynchronous communications port异步通信端口Attachment附件BBar code条形码Bar code reader条形码读卡器Basic application基础程序Binary coding schemes二进制译码方案Binary system二进制系统Bit比特Browser浏览器Bus line总线Backup tape cartridge units备份磁带盒单元Bandwidth带宽Bluetooth蓝牙Broadband宽带Browser浏览器Business-to-business企业对企业电子商务Business-to-consumer企业对消费者Bus总线CCables连线Cell单元箱Chain printer链式打印机Character and recognition device字符标识识别设备Chart图表Chassis支架Chip芯片Clarity清晰度Closed architecture封闭式体系结构Column列Combination key结合键computer competency计算机能力connectivity连接,结点Continuous-speech recognition system连续语言识别系统Control unit操纵单元Cordless or wireless mouse无线鼠标Cable modems有线调制解调器carpal tunnel syndrome腕骨神经综合症CD-ROM可记录光盘CD-RW可重写光盘CD-R可记录压缩光盘Channel信道Chat group谈话群组chlorofluorocarbons(CFCs) ]氯氟甲烷Client客户端Coaxial cable同轴电缆cold site冷战Commerce servers商业服务器Communication channel信道Communication systems信息系统Compact disc rewritableCompact disc光盘computer abuse amendments act of 19941994计算机滥用法案computer crime计算机犯罪computer ethics计算机道德computer fraud and abuse act of 1986计算机欺诈和滥用法案computer matching and privacy protection act of 1988计算机查找和隐私保护法案Computer network计算机网络computer support specialist计算机支持专家computer technician计算机技术人员computer trainer计算机教师Connection device连接设备Connectivity连接Consumer-to-consumer个人对个人cookies-cutter programs信息记录截取程序cookies信息记录程序 cracker解密高手cumulative trauma disorder积累性损伤错乱Cybercash电子现金Cyberspace计算机空间cynic愤世嫉俗者DDatabase数据库database files数据库文件Database manager数据库管理Data bus数据总线Data projector数码放映机Desktop system unit台式电脑系统单元Destination file目标文件Digital cameras数码照相机Digital notebooks数字笔记本Digital bideo camera数码摄影机Discrete-speech recognition system不连续语言识别系统Document文档document files文档文件Dot-matrix printer点矩阵式打印机Dual-scan monitor双向扫描显示器Dumb terminal非智能终端data security数据安全Data transmission specifications数据传输说明database administrator数据库管理员Dataplay数字播放器Demodulation解调denial of service attack拒绝服务攻击Dial-up service拨号服务Digital cash数字现金Digital signals数字信号Digital subscriber line数字用户线路Digital versatile disc数字化通用磁盘Digital video disc数字化视频光盘Direct access直接存取Directory search目录搜索disaster recovery plan灾难恢复计划Disk caching磁盘驱动器高速缓存Diskette磁盘Disk磁碟 Distributed data processing system分部数据处理系统Distributed processing分布处理Domain code域代码Downloading下载DVD 数字化通用磁盘DVD-R 可写DVDDVD-RAM DVD随机存取器DVD-ROM 只读DVDEe-book电子阅读器Expansion cards扩展卡end user终端用户e-cash电子现金e-commerce电子商务electronic cash电子现金electronic commerce电子商务electronic communications privacy act of1986电子通信隐私法案encrypting加密术energy star能源之星Enterprise computing企业计算化environment环境Erasable optical disks可擦除式光盘ergonomics人类工程学ethics道德规范External modem外置调制解调器extranet企业外部网FFax machine传真机Field域Find搜索FireWire port port火线端口Firmware固件Flash RAM闪存Flatbed scanner台式扫描器Flat-panel monitor纯平显示器 floppy disk软盘Formatting toolbar格式化工具条Formula公式Function函数fair credit reporting act of 1970公平信用报告法案Fiber-optic cable光纤电缆File compression文件压缩File decompression文件解压缩filter过滤firewall防火墙firewall防火墙Fixed disk固定硬盘Flash memory闪存Flexible disk可折叠磁盘Floppies磁盘Floppy disk软盘Floppy-disk cartridge磁盘盒Formatting格式化freedom of information act of 1970信息自由法案frustrated受挫折Full-duplex communication全双通...
做在线考试系统,如何实现word,Excel的
实现打印功能的核心是PrintDocument类这个类属于System.Drawing.Printing名字空间这个类封装了当前的打印设置页面设置以及所有的与打印有关的事件和方法这个类包括以下几个属性 事件 和方法1、PrinterSettings 属性 存放打印机的设置信息这个属性不需要程序员设置因为它是由打印对话框获取的 2、PrintCountroller 属性 控制打印过程3、DefaultPageSettings 属性 存放页面设置信息 打印纸大小方向等也不需要程序员设置因为它是由页面设置对话框获取的4、DocumentName 属性 指定文档名称,出现在打印机状态窗口中 1。
BeginPrint事件 在打印之前发出2. PrintPage事件 每打印一页是发出,事件接受一个PrintPageEventArgs参数该参数封装了打印相关的信息 PrintPageEventArgs参数有很多重要的属性 1 Cancel 取消打印 2 Graphics 页面的绘图对象 3 HasMorePages 是否还有要打印的页面Print 方法 该方法没有参数 调用它将按照当前设置开始打印 若实现打印功能首先构造PrintDocument对象添加打印事件PrintDocument printDocument;private void InitializeComponent(){...printDocument=new PrintDocument();printDocument.PrintPage += new PrintPageEventHandler (this.printDocument_PrintPage);...}实现打印事件功能打印和绘图类似都是调用Graphics 类的方法进行画图 不同的是一个在显示器上一个在打印纸上并且打印要进行一些复杂的计算如换行 分页等。
private void printDocument_PrintPage(object sender,PrintPageEventArgs e){StringReader lineReader = new StringReader(textBox.Text);Graphics g = e.Graphics; //获得绘图对象float linesPerPage = 0; //页面的行号float yPosition = 0; //绘制字符串的纵向位置int count = 0; //行计数器float leftMargin = e.MarginBounds.Left; //左边距float topMargin = e.MarginBounds.Top; //上边距string line = null; 行字符串Font printFont = this.textBox.Font; //当前的打印字体SolidBrush myBrush = new SolidBrush(Color.Black);//刷子linesPerPage = e.MarginBounds.Height / printFont.GetHeight(g);//每页可打印的行数//逐行的循环打印一页 while(count < linesPerPage && ((line=lineReader.ReadLine()) != null)) { yPosition = topMargin + (count * printFont.GetHeight(g)); g.DrawString(line, printFont, myBrush, leftMargin, yPosition, new StringFormat()); count++; }如果本页打印完成而line不为空说明还有没完成的页面这将触发下一次的打印事件在下一次的打印中lineReader会自动读取上次没有打印完的内容因为lineReader是这个打印方法外的类的成员它可以记录当前读取的位置 if(line != null) e.HasMorePages = true; else e.HasMorePages = false; }打印设置,构造打印对话框 将对话框中设置的Document属性赋给printDocument这样会将用户的设置自动保存到printDocument的PrinterSettings属性中protected void FileMenuItem_PrintSet_Click(object sender,EventArgs e){PrintDialog printDialog = new PrintDialog();printDialog.Document = printDocument;printDialog.ShowDialog();}页面设置和打印预览与打印设置原理相同都是构造对话框将用户在对话框中的设置保存到相应的类的属性中protected void FileMenuItem_PageSet_Click(object sender,EventArgs e){ PageSetupDialog pageSetupDialog = new PageSetupDialog(); pageSetupDialog.Document = printDocument; pageSetupDialog.ShowDialog();}打印预览protected void FileMenuItem_PrintView_Click(object sender,EventArgs e){ PrintPreviewDialog printPreviewDialog = new PrintPreviewDialog(); printPreviewDialog.Document = printDocument; try { printPreviewDialog.ShowDialog(); } catch(Exception excep) { MessageBox.Show(excep.Message, "打印出错", MessageBoxButtons.OK, MessageBoxIcon.Error); }}打印就可以直接调用printDocument的Print()方法因为用户可能在打印之前还要再更改打印设置所以在这里再次显示打印设置对话框 protected void FileMenuItem_Print_Click(object sender,EventArgs e) { PrintDialog printDialog = new PrintDialog(); printDialog.Document = printDocument; lineReader = new StringReader(textBox.Text); if (printDialog.ShowDialog() == DialogResult.OK) { try { printDocument.Print(); } catch(Exception excep) { MessageBox.Show(excep.Message, "打印出错", MessageBoxButtons.OK, MessageBoxIcon.Error); printDocument.PrintController.OnEndPrint(printDocument,new PrintEventArgs()); } } }总结打印的过程是 1 在应用程序窗体初始化时构造PrintDocument对象 添加 printDocument 的 PrintPage 方法 2 实现PrintPage方法 4 在用户的单击事件中调用 printDocument 的 Print方法实现打印功能在这中间可能要用到 PrintDialog PrintPreviewDialog PageSetupDialog 设置和查看打印效
java(web)打印 通常是怎么实现的
展开全部 Web系统中,打印功能一直是个老大难问题,因此产生了很多第三方的控件,多数要收费,而且跟自己的系统结合有一定的麻烦。
系统采用J2EE技术,jsp打印问题同样存在于OA中。
打印方式有三种:一是不经过任何修改,直接调用javascript中的window.print()打印。
二根据客户要求的报表格式,编写相应格式的html,装载数据打印,同样调用window.print()打印,只是对html的格式要求比较高。
三是通过客户提供的word格式,通过xml配置文件与数据库的数据进行关联,自动装载数据到word中打印,这里是利用客户端的word进行打印。
第一种几乎不用编写程序,最简单快捷,这里会遇到几个问题,只能打印表单内容,按钮不希望打印出来;页眉页脚不想打印出来;IE的titile不想打印出来。
解决办法:把button放在一个table或者div里,打印的时候隐藏,完成后显示就可以。
系统中的javascript打印代码如下:function Print() { var tit = document.title; document.title = ""; table1.style.display = "none"; window.print(); document.title = tit; table1.style.display = "";}不过只能起到打印的目的,打印的效果一般比较土。
不管怎么说,可以最快的让系统的大部分模块都有打印的功能。
第二种方式必须根据每个报表的格式进行定制html和java程序开发,会花比较多的时间。
要注意的是对html中table的样式控制,在IE中浏览看起来很细的边框,打印出来有些线条会比较粗,有些线条又会比较细,阴阳怪气的很难看。
在table中直接用bordercolor会让线条显得很粗,用bordercolorlight,bordercolordark配合使用可以显示出秀气的线条。
姓名 所属部门 陈 技术部 比如以上代码,在IE中看起来线条一样大小,还是比较秀气。
不要高兴的太早,打印出来的效果不象在IE中看到的那样,边框虽细,内线却很粗!原因是每个td都有边框,td与td的交接处就会有线条重叠,虽然IE看起来没有,可是打印的时候就会显示出来。
这个问题的解决办法是控制每一个td的样式,对重叠的地方进行border-bottom:1px之类的控制。
这个方案比较消耗精力,而且打印的时候很难控制分页,更不能随时按照客户的需要调整字体边框颜色等。
第三种方案:从服务器端生成word、excel等文档,发送到浏览器进行打印实现过程:先将需要打印的数据导入到word或者excel中,再利用word或者excel的打印功能来实现web打印。
下面以excel为例实现如何打印的过程 将网页中数据导入excel中的方法有很多,这里先介绍一种,利用ActiveX控件的方式,即 Excel.Application, 这个控件是MS为excel提供的编程接口,在很多种编程语言种都可以通过该接口来操纵excel表格。
下面用javascript脚本来实现一个简单的例子。
function ExcelPrint() { var excelApp; //存放Excel对象 var excelBook; //存放Excel工件簿文件 var excelSheet; //存放Excel活动工作表 try { excelApp = new ActiveXObject("Excel. Application"); //创建Excel对象} catch(e) { alert("请启用ActiveX控件设置!"); return; } excelBook = excelApp.Workbooks.Add(); //创建Excel工作簿文件 excelSheet = excelBook.ActiveSheet; //激活Excel工作表 var rowLen = printTable.rows.length; //table对象的行数 for (var i = 0; i 注意: 运行该程序的前提是 IE要允许对没有标记为安全的Activex控件进行初始化和脚本运行。
设置方法如下: 打开控制面板→Internet选项→安全性→自定义级别→对没有标记为安全的ActiveX控件进行初始化和脚本运行→选中启用,这样我们的程序就可以运行了。
如果没有启用该ActiveX控件设置,那么程序在执行创建Excel对象时会抛出一个异常,这时可以通过catch()语句来捕获这个异常,并且做出相应的处理。
运行该程序必须客户端安装了MS EXCEL,否则Activex驱动不了。
转载请注明出处51数据库 » word printpreview