请以word文档打印 英语怎么说
先添加引用 COM组件里的WordMicrosoft.Office.Interop.Word.Application app = new Application();Microsoft.Office.Interop.Word.Document doc = new Document();string path = "你的WORD文档的路径";if (System.IO.File.Exists(path))//如果文档存在则删除{System.IO.File.Delete(path);}
print to PDF Document是怎么回事,怎样取消
如果楼主不想用软件的话,可以分几次批打,就是你一次选中二十个左右的word文档,然后点击右键,在弹出的对话框中有一个打印,直接点打印就是了。
如果楼主想用软件的话,嘻皮客娱乐学习网实用工具版块有一个可以批打office文档的软件。
楼主自己去下载或是留个邮箱我发给你。
PHP读取word文档内容的方法
jeyyu的代码中浏览器中执行时需要降低浏览器的安全设置,不方便,而且取得的内容只是到剪贴板你可以试试SOAOffice中间件,这个是专门读写word的类,联系科翰索要php代码示例 你说的是端口问题吧,最近SOAOffice中间件推出了免端口版本。
个人体会,SOAOffice编程调用上,要比金格的全文批注简单得多
关于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# 打印问题
1,在Form中加入一个印刷的控件PrintDocument,取名为MyPrintDocument2,新建一个一般类(不是窗体类),名叫MyPrinter,内容如下: public class MyPrinter { private PrintDocument ThePrintDocument; private Font titleFont; private Font theFont; private Color FontColor; private float CurrentY; static int PageNumber; private int PageWidth; private int PageHeight; private int LeftMargin; private int TopMargin; private int RightMargin; private int BottomMargin; private ArrayList textList = new ArrayList(); private int currentIndex = 0; public MyPrinter(PrintDocument _thePrintDocument, Font _theFont, Font _titleFont,Color _FontColor, ArrayList _textList) { ThePrintDocument = _thePrintDocument; theFont = _theFont; titleFont = _titleFont; FontColor = _FontColor; PageNumber = 0; textList = _textList; if (!ThePrintDocument.DefaultPageSettings.Landscape) { PageWidth = ThePrintDocument.DefaultPageSettings.PaperSize.Width; PageHeight = ThePrintDocument.DefaultPageSettings.PaperSize.Height; } else { PageHeight = ThePrintDocument.DefaultPageSettings.PaperSize.Width; PageWidth = ThePrintDocument.DefaultPageSettings.PaperSize.Height; } LeftMargin = ThePrintDocument.DefaultPageSettings.Margins.Left; TopMargin = ThePrintDocument.DefaultPageSettings.Margins.Top; RightMargin = ThePrintDocument.DefaultPageSettings.Margins.Right; BottomMargin = ThePrintDocument.DefaultPageSettings.Margins.Bottom; } public bool DrawDocument(Graphics g) { try { DrawHeader(g); bool bContinue = DrawItems(g); g.Dispose(); return bContinue; } catch (Exception ex) { MessageBox.Show("失败" + ex.Message.ToString(), " - Error", MessageBoxButtons.OK, MessageBoxIcon.Error); g.Dispose(); return false; } } public void DrawHeader(Graphics g) { CurrentY = (float)TopMargin; PageNumber++; string PageString = "第" + PageNumber+"页"; StringFormat PageStringFormat = new StringFormat(); PageStringFormat.Trimming = StringTrimming.Word; PageStringFormat.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit | StringFormatFlags.NoClip; PageStringFormat.Alignment = StringAlignment.Far; RectangleF PageStringRectangle = new RectangleF((float)LeftMargin, CurrentY, (float)PageWidth - (float)RightMargin - (float)LeftMargin, g.MeasureString(PageString, theFont).Height); g.DrawString(PageString, theFont, new SolidBrush(Color.Black), PageStringRectangle, PageStringFormat); CurrentY += g.MeasureString(PageString, theFont).Height; StringFormat TitleFormat = new StringFormat(); TitleFormat.Trimming = StringTrimming.Word; TitleFormat.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit | StringFormatFlags.NoClip; TitleFormat.Alignment = StringAlignment.Center; RectangleF TitleRectangle = new RectangleF((float)LeftMargin, CurrentY, (float)PageWidth - (float)RightMargin - (float)LeftMargin, g.MeasureString("收费单", titleFont).Height); g.DrawString("收费单",titleFont,new SolidBrush(FontColor),TitleRectangle,TitleFormat); CurrentY +=g.MeasureString("收费单",titleFont).Height; } public bool DrawItems(Graphics g) { StringFormat TextFormat = new StringFormat(); TextFormat.Trimming = StringTrimming.Word; TextFormat.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit | StringFormatFlags.NoClip; TextFormat.Alignment = StringAlignment.Near; for (int i = currentIndex; i { string var = textList[i].ToString(); RectangleF TextRectangle = new RectangleF((float)LeftMargin, CurrentY, (float)PageWidth - (float)RightMargin - (float)LeftMargin, g.MeasureString("收费单", titleFont).Height); g.DrawString(var, theFont, new SolidBrush(FontColor), TextRectangle, TextFormat); CurrentY = CurrentY + g.MeasureString(var, theFont).Height; if ((int)CurrentY > (PageHeight - TopMargin - BottomMargin)) { currentIndex = i+1; return true; } } return false; } }3,回到原来的Form中,给MyPrintDocument添加PrintPage事件 private void MyPrintDocument_PrintPage(object sender, PrintPageEventArgs e) { bool hasNextPage = mp.DrawDocument(e.Graphics); if (hasNextPage) { e.HasMorePages = true; } }4,撰写打印机设置对话框函数 private bool SetupThePrinting() { PrintDialog MyPrintDialog = new PrintDialog(); MyPrintDialog.AllowCurrentPage = false; MyPrintDialog.AllowPrintToFile = false; MyPrintDialog.AllowSelection = false; MyPrintDialog.AllowSomePages = false; MyPrintDialog.PrintToFile = false; MyPrintDialog.ShowHelp = false; MyPrintDialog.ShowNetwork = false; if (MyPrintDialog.ShowDialog() != DialogResult.OK) return false; ...
VB.NET或C#如何调用某个打印机(例如"Microsoft XPS Document ...
实现打印功能的核心是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怎么实现在线打开word时给word加水印?
package com.ymo.word; import com.jacob.activeX.ActiveXComponent; import com.jacob.com.ComThread; import com.jacob.com.Dispatch; import com.jacob.com.Variant; public class TestJacobWord { private ActiveXComponent wrdCom = null; private Dispatch doc = null; private Dispatch activeDoc = null; private Dispatch docSelect = null; private Dispatch docs = null; private static TestJacobWord instance = null; private String docName = ""; public static TestJacobWord getInstance() { if (instance == null) { instance = new TestJacobWord(); } return instance; } private boolean initWord() { boolean flag = false; ComThread.InitSTA(); wrdCom = new ActiveXComponent("word.Application"); try { docs = wrdCom.getProperty("Documents").toDispatch(); wrdCom.setProperty("Visible", new Variant(false)); flag = true; } catch (Exception e) { flag = false; e.printStackTrace(); } return flag; } private void createNewDocument() { doc = Dispatch.call(docs, "Add").toDispatch(); docSelect = Dispatch.get(wrdCom, "Selection").toDispatch(); } private void getActiveDoc() { activeDoc = wrdCom.getProperty("ActiveWindow").toDispatch(); System.out.println(activeDoc.getProgramId()); } private void openDocument(String docPath) { if (this.doc != null) { closeDocument(); } this.doc = Dispatch.call(docs, "Open", docPath, new Variant(false),new Variant(false)).toDispatch(); docSelect = Dispatch.get(wrdCom, "Selection").toDispatch(); } private void closeDocument() { if (doc != null) { Dispatch.call(doc, "Save"); Dispatch.call(doc, "Close", new Variant(true)); doc = null; } } private void setImgWaterMark(String waterMarkPath) { Dispatch activePan = Dispatch.get(activeDoc, "ActivePane").toDispatch(); Dispatch view = Dispatch.get(activePan, "View").toDispatch(); Dispatch.put(view, "SeekView", new Variant(9)); Dispatch headfooter = Dispatch.get(docSelect, "HeaderFooter").toDispatch();// 取得图形对象 Dispatch shapes = Dispatch.get(headfooter, "Shapes").toDispatch(); Dispatch pic = Dispatch.call(shapes, "AddPicture", waterMarkPath).toDispatch(); Dispatch.call(pic, "Select"); Dispatch.put(pic, "Left", new Variant(10)); Dispatch.put(pic, "Top", new Variant(200)); Dispatch.put(pic, "Width", new Variant(150)); Dispatch.put(pic, "Height", new Variant(80)); Dispatch.put(view, "SeekView", new Variant(0)); } public void setTextWaterMark(String waterMarkStr) { Dispatch activePan = Dispatch.get(activeDoc, "ActivePane").toDispatch(); Dispatch view = Dispatch.get(activePan, "View").toDispatch(); Dispatch.put(view, "SeekView", new Variant(9)); Dispatch headfooter = Dispatch.get(docSelect, "HeaderFooter").toDispatch(); Dispatch shapes = Dispatch.get(headfooter, "Shapes").toDispatch(); Dispatch selection = Dispatch.call(shapes, "AddTextEffect",new Variant(9), waterMarkStr, "宋体", new Variant(1),new Variant(false), new Variant(false), new Variant(0),new Variant(0)).toDispatch(); Dispatch.call(selection, "Select"); Dispatch shapeRange = Dispatch.get(docSelect, "ShapeRange").toDispatch(); Dispatch.put(shapeRange, "Name", "PowerPlusWaterMarkObject1"); Dispatch textEffect = Dispatch.get(shapeRange, "TextEffect").toDispatch(); Dispatch.put(textEffect, "NormalizedHeight", new Boolean(false)); Dispatch line = Dispatch.get(shapeRange, "Line").toDispatch(); Dispatch.put(line, "Visible", new Boolean(false)); Dispatch fill = Dispatch.get(shapeRange, "Fill").toDispatch(); Dispatch.put(fill, "Visible", new Boolean(true));// 设置水印透明度 Dispatch.put(fill, "Transparency", new Variant(0.5)); Dispatch foreColor = Dispatch.get(fill, "ForeColor").toDispatch(); Dispatch.put(foreColor, "RGB", new Variant(16711620)); Dispatch.call(fill, "Solid");// 设置水印旋转 Dispatch.put(shapeRange, "Rotation", new Variant(315)); Dispatch.put(shapeRange, "LockAspectRatio", new Boolean(true)); Dispatch.put(shapeRange, "Height", new Variant(117.0709)); Dispatch.put(shapeRange, "Width", new Variant(468.2835)); Dispatch.put(shapeRange, "Left", new Variant(-999995)); Dispatch.put(shapeRange, "Top", new Variant(-999995)); Dispatch wrapFormat = Dispatch.get(shapeRange, "WrapFormat").toDispatch();// 是否允许交叠 Dispatch.put(wrapFormat, "AllowOverlap", new Variant(true)); Dispatch.put(wrapFormat, "Side", new Variant(3)); Dispatch.put(wrapFormat, "Type", new Variant(3)); Dispatch.put(shapeRange, "RelativeHorizontalPositi on", new Variant(0)); Dispatch.put(shapeRange, "RelativeVerticalPosition", new Variant(0)); Dispatch.put...
你曾今碰到“用VB实现一个打印WORD文档功能。
。
。
”这个问题...
VB.NET(2005)中打印WORD文档(.doc)有两种方法可以完成,无论哪一种,你都得安装office,呵呵。
Imports Microsoft.Office.CoreImports Word = Microsoft.Office.Interop.Word第一种,允许用户更换打印机等设置,这是很重要的。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click PrintDialog1.AllowCurrentPage = False '不打印当前页 PrintDialog1.AllowSelection = False '不允许打印部分页等 PrintDialog1.AllowSomePages = False If PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then Dim poApp As Word.Application Dim poDoc As Word.Document poApp = New Word.Application poApp.Visible = False poApp.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone poDoc = poApp.Documents.Open("d:\1.doc")poApp.WordBasic.FilePrintSetup(Printer:=PrintDialog1.PrinterSettings.PrinterName, DoNotSetAsSysDefault:=1) 'DoNotSetAsSysDefault:=0就会修改默认打印机 ''poApp.ActivePrinter = PrintDialog1.PrinterSettings.PrinterName poApp.PrintOut()poDoc.Close(Word.WdSaveOptions.wdDoNotSaveChanges) 'clean up poDoc = Nothing 'close word这里有个极其重要的参数WdSaveOptions,它有三个值:wdDoNotSaveChanges、wdDoNotSaveChanges和wdPromptToSaveChanges。
当选择wdDoNotSaveChanges时,文档就会来不及输出到打印机而关闭,当选择wdPromptToSaveChanges时,word程序有时就会无法退出!poApp.Quit()语句也是不可取的,因为默认的是wdPromptToSaveChanges。
poApp.Quit(Word.WdSaveOptions.wdPromptToSaveChanges) poApp = Nothing End If End Sub第二种,是调用windows打开的方式,很快,但是不幸的是不能更换打印机。
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim MyProcess As New Process MyProcess.StartInfo.CreateNoWindow = False MyProcess.StartInfo.Verb = "print" MyProcess.StartInfo.FileName = "d:\1.doc" MyProcess.Start() MyProcess.WaitForExit(10000) MyProcess.CloseMainWindow() MyProcess.Close() End Sub***********************VB6下使用的方法:Private Sub Form_Load()Set Word1 = CreateObject("word.application")Word1.Documents.Open App.Path & "\1.doc"Word1.Visible = TrueWord1.PrintOutWord1.Application.QuitEnd Sub
转载请注明出处51数据库 » printdocument word
智商略显捉急