usingsystem1_第1页
usingsystem1_第2页
usingsystem1_第3页
usingsystem1_第4页
usingsystem1_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

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

文档简介

1、最新资料推荐using systemusing System; using System.Collections.Generic; usingSystem.ComponentModel; using System.Data; usingSystem.Drawing; using System.Linq; using System.Text; usingusing Word = using Excel=usingPowerPoint=namespace test class Form3 : Form public Form3() InitializeComponent();System.Wind

2、ows.Forms; using System.Threading; using System.IO;using Microsoft.Office.Core;Microsoft.Office.Interop.Word;Microsoft.Office.Interop.Excel;Microsoft.Office.Interop.PowerPoint; public partialSystem.Windows.Forms.Control.CheckForIllegalCrossThreadCall/ToolTipfalse;this.CheckForIllegalCrossThreadCalls

3、 string file_extend = string.Empty;tool_showinfo = new ToolTip();CopyFile copyfile;private void Form3_Load(object sender, EventArgs e)copyfile = new CopyFile(listBox1,private voidEventArgs e)sender,listView1); button1_Click(object1 / 10Thread t = new Thread(copyfile.copy);t.Start(); Thread.Sleep(500

4、0); private void button2_Click(object sender, EventArgs e) private void button3_Click(objectsender, EventArgs e) public class CopyFile public CopyFile(ListBoxlistBox1,ListViewlistView1)this.listBox1= listBox1;this.listView1 = listView1; string dir =C:a;string d = d:a;private ListBoxlistBox1;private

5、ListViewlistView1;/Word 转 a 换 ?成 pdf/ summary /把?Word 文?件 t 转 a 换?成为 aPDF格?式?文?件 t/summary / param name=sourcePath 源 文 ? 件 t 路 径?/param/ param name=targetPath目?标文 ?件 t 路径 ?/param/ returnstrue= 转 a 换 ? 成功 |/returnsprivate bool DOCConvertToPDF(string sourcePath, string targetPath) bool result = false;

6、Microsoft.Office.Interop.Word.WdExportFormat exportFormat = Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormat PDF; object paramMissing = Type.Missing;Word.ApplicationClasswordApplicationnew最新资料推荐Microsoft.Office.Interop.Word.ApplicationClass();Microsoft.Office.Interop.Word.Document wordDoc

7、ument = null;try object paramSourceDocPath= sourcePath;string paramExportFilePath =targetPath;Microsoft.Office.Interop.Word.WdExportFormat paramExportFormat = exportFormat; bool paramOpenAfterExport = false;Word.WdExportOptimizeForparamExportOptimizeFor=Word.WdExportOptimizeFor.wdExportOptimizeForPr

8、int;Word.WdExportRangeparamExportRange=Word.WdExportRange.wdExportAllDocument; int paramStartPage = 0;int paramEndPage = 0;Word.WdExportItem paramExportItem = Word.WdExportItem.wdExportDocumentContent;bool paramIncludeDocProps = true; bool paramKeepIRM = true; Word.WdExportCreateBookmarks paramCreat

9、eBookmarks = Word.WdExportCreateBookmarks.wdExportCreateWordBookmarks; bool paramDocStructureTags = true;boolparamBitmapMissingFonts = true; bool3 / 10wordDocument =paramUseISO19005_1 = false;wordApplication.Documents.Open( refparamSourceDocPath,refparamMissing,refparamMissing,refparamMissing,refpar

10、amMissing,refparamMissing,refparamMissing,refparamMissing,refparamMissing,refparamMissing,refparamMissing,refparamMissing,refparamMissing,refparamMissing,refparamMissing,refparamMissing);if(wordDocument != null)wordDocument.ExportAsFixedFormat(paramExportFilePath, paramExportFormat, paramOpenAfterEx

11、port, paramExportOptimizeFor, paramExportRange, paramStartPage, paramEndPage, paramExportItem, paramIncludeDocProps, paramKeepIRM, paramCreateBookmarks, paramDocStructureTags, paramBitmapMissingFonts, paramUseISO19005_1, ref paramMissing); result = true;/ textBox1.Text += DateTime.Now.ToString() + t

12、 + sourcePath+ 转 a 换 ? 成 功 | + rn; this.listView1.Items.Add(成 功 |);catch /textBox1.Text +=false;DateTime.Now.ToString() + t + sourcePath + 转 a 换?失败 + rn; this.listView1.Items.Add( 失败 ); result =finally最新资料推荐if (wordDocument != null)wordDocument.Close(ref paramMissing,refparamMissing,refparamMissing)

13、;wordDocument = null;if(wordApplication!=null)wordApplication.Quit(ref paramMissing,refparamMissing,refparamMissing);wordApplicationnull;GC.Collect();GC.WaitForPendingFinalizers();GC.Collect();GC.WaitForPendingFinalizers();return result; / summary /把?Excel 文?件 t 转 a 换?成 PDF 格?式?文?件 t/summary/ param

14、name=sourcePath 源 文 ? 件径?/param/ param name=targetPath目?标文?件径 ?/param/ returnstrue= 转a 换 ? 成功 |/returnsprivate bool XLSConvertToPDF(stringsourcePath, stringtargetPath) bool result = false;targetTypeMicrosoft.Office.Interop.Excel.XlFixedFormatTypeMicrosoft.Office.Interop.Excel.XlFixedFormatType.xlTyp

15、ePDF;5 / 10objectmissingType.Missing;Microsoft.Office.Interop.Excel.ApplicationClass application= null; Microsoft.Office.Interop.Excel.Workbook workBook = null; try application = new Microsoft.Office.Interop.Excel.ApplicationClass();object type =workBook =object target = targetPath; targetType;appli

16、cation.Workbooks.Open(sourcePath, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);workBook.ExportAsFixedFormat(targetType, target, Excel.XlFixedFormatQuality.xlQualityStandard, true, false, missing, missing, missing, missi

17、ng); result = true; / textBox1.Text +=DateTime.Now.ToString()+ t + sourcePath + 转 a 换?成功 | + rn;this.listView1.Items.Add( 成 功 |);catch / textBox1.Text +=false;DateTime.Now.ToString() + t + sourcePath + 转 a 换?失败 + rn; this.listView1.Items.Add(失败 );result =finally最新资料推荐if(workBook != null)workBook.Clo

18、se(true,missing, missing);workBook =null; if(application!=null)application.Quit();application = null; GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect();GC.WaitForPendingFinalizers(); return result; / summary / 把?PowerPoing 文?件 t 转 a 换?成 PDF格?式 ?文?件 t/summary / param name=sourcePath 源 文 ? 件 t

19、 路 径?/param/ param name=targetPath目?标文 ?件 t 路径 ?/param/ returnstrue= 转 a 换 ? 成功 |/returnsprivate bool PPTConvertToPDF(string sourcePath, string targetPath) bool result; Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType targetFileType = Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSave A

20、sPDF; object missing = Type.Missing; Microsoft.Office.Interop.PowerPoint.ApplicationClass7 / 10application = null;Microsoft.Office.Interop.PowerPoint.Presentationpersentation = null; try application = newMicrosoft.Office.Interop.PowerPoint.ApplicationClass();persentation = application.Presentations.

21、Open(sourcePath,MsoTriState.msoTrue,MsoTriState.msoFalse,MsoTriState.msoFalse);persentation.SaveAs(targetPath, targetFileType, Microsoft.Office.Core.MsoTriState.msoTrue);result = true; / textBox1.Text += DateTime.Now.ToString() + t + sourcePath + 转 a 换?成功 | + rn; this.listView1.Items.Add( 成 功 |); catch / textBox1.Text += DateTime.Now.ToString() + t + sourcePath + 转 a 换?失败 + rn;this.listView1.Items.Add(失败 );res

温馨提示

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

评论

0/150

提交评论