C#中如何利用word对象进行打印?? 我以前一直用VB,最近在学C#。在VB中可以利用word对象进行合同的打印。不只在C#中该如何处理打印问题?我看C#中也可以引用word对象,但不知该如何实现调用word对象进行打印?我是新手,有些东西还不是很明白,如果有问错的地方,大家别见笑!希望可以得到你们的帮助指点!多谢了!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这是一个打开Word的方法,打印的话,Word.Document对象有PrintOut()方法,基本把VB的代码改改就能用using Word; Word.Application wdApp = null; static object missing = Missing.Value; private Word.Document OpenFile(string filePath) { Word.Document wdDoc = null; object fileName = filePath; object confirmConversions = missing; object readOnly = true; object addToRecentFiles = missing; object passwordDocument = missing; object passwordTemplate = missing; object revert = missing; object writePasswordDocument = missing; object writePasswordTemplate = missing; object format = missing; object encoding = missing; object visible = false; object openAndRepair = missing; object documentDirection = missing; object noEncodingDialog = missing; wdDoc = wdApp.Documents.Open( ref fileName , ref confirmConversions , ref readOnly , ref addToRecentFiles , ref passwordDocument , ref passwordTemplate , ref revert , ref writePasswordDocument , ref writePasswordTemplate , ref format , ref encoding , ref visible , ref openAndRepair , ref documentDirection , ref noEncodingDialog ); wdDoc.Activate(); return wdDoc; } Word.Application wordApplication = new Word.Application(); Word.Document thisDocument = new Word.Document(); object missingValue = Type.Missing; object myTrue = true; object fileName = "\\TestFile1.rtf"; wordApplication.Visible = true; thisDocument = wordApplication.Documents.Open(ref fileName, ref missingValue, ref myTrue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue);Object background = Type.Missing;Object append = Type.Missing;Object range = Type.Missing;Object outputFileName = Type.Missing;Object from = Type.Missing;Object to = Type.Missing;Object item = Type.Missing;Object copies = Type.Missing;Object pages = Type.Missing;Object pageType = Type.Missing;Object printToFile = Type.Missing;Object collate = Type.Missing;Object fileName = Type.Missing;Object activePrinterMacGX = Type.Missing;Object manualDuplexPrint = Type.Missing;Object printZoomColumn = Type.Missing;Object printZoomRow = Type.Missing;Object printZoomPaperWidth = Type.Missing;Object printZoomPaperHeight = Type.Missing;ThisDocument.PrintOut(ref background, ref append, ref range, ref outputFileName, ref from, ref to, ref item, ref copies, ref pages, ref pageType, ref printToFile, ref collate, ref fileName, ref activePrinterMacGX, ref manualDuplexPrint, ref printZoomColumn, ref printZoomRow, ref printZoomPaperWidth, ref printZoomPaperHeight); 托管对象是否存在像句柄那样的唯一标识 数字证书读取 Winform 实例化类的对象之后,无法释放内存,可能是C#的一个Bug! 急急急,两个winform项目间如何交互? irisSkin2.dll的使用 正则表达式 急 关于板卡API函数的封装 C#飞机类游戏有没有代码或网站 HZ 会WCF的进。。。 C#操作word的问题 c#会使用正则表达式的近来 C#里的哪个类可以获得指定URL的HTML?
基本把VB的代码改改就能用using Word; Word.Application wdApp = null;
static object missing = Missing.Value; private Word.Document OpenFile(string filePath)
{ Word.Document wdDoc = null; object fileName = filePath;
object confirmConversions = missing;
object readOnly = true;
object addToRecentFiles = missing;
object passwordDocument = missing;
object passwordTemplate = missing;
object revert = missing;
object writePasswordDocument = missing;
object writePasswordTemplate = missing;
object format = missing;
object encoding = missing;
object visible = false;
object openAndRepair = missing;
object documentDirection = missing;
object noEncodingDialog = missing; wdDoc = wdApp.Documents.Open(
ref fileName ,
ref confirmConversions ,
ref readOnly ,
ref addToRecentFiles ,
ref passwordDocument ,
ref passwordTemplate ,
ref revert ,
ref writePasswordDocument ,
ref writePasswordTemplate ,
ref format ,
ref encoding ,
ref visible ,
ref openAndRepair ,
ref documentDirection ,
ref noEncodingDialog ); wdDoc.Activate();
return wdDoc;
}
Word.Document thisDocument = new Word.Document();
object missingValue = Type.Missing;
object myTrue = true;
object fileName = "\\TestFile1.rtf";
wordApplication.Visible = true; thisDocument = wordApplication.Documents.Open(ref fileName, ref missingValue,
ref myTrue, ref missingValue, ref missingValue, ref missingValue,
ref missingValue, ref missingValue, ref missingValue,
ref missingValue, ref missingValue, ref missingValue,
ref missingValue, ref missingValue, ref missingValue);
Object background = Type.Missing;
Object append = Type.Missing;
Object range = Type.Missing;
Object outputFileName = Type.Missing;
Object from = Type.Missing;
Object to = Type.Missing;
Object item = Type.Missing;
Object copies = Type.Missing;
Object pages = Type.Missing;
Object pageType = Type.Missing;
Object printToFile = Type.Missing;
Object collate = Type.Missing;
Object fileName = Type.Missing;
Object activePrinterMacGX = Type.Missing;
Object manualDuplexPrint = Type.Missing;
Object printZoomColumn = Type.Missing;
Object printZoomRow = Type.Missing;
Object printZoomPaperWidth = Type.Missing;
Object printZoomPaperHeight = Type.Missing;ThisDocument.PrintOut(ref background, ref append,
ref range, ref outputFileName, ref from, ref to,
ref item, ref copies, ref pages, ref pageType,
ref printToFile, ref collate, ref fileName, ref activePrinterMacGX,
ref manualDuplexPrint, ref printZoomColumn, ref printZoomRow,
ref printZoomPaperWidth, ref printZoomPaperHeight);