已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Threading;using System.IO;using Microsoft.Office.Core;using Word = Microsoft.Office.Interop.Word;using Excel = Microsoft.Office.Interop.Excel;using PowerPoint = Microsoft.Office.Interop.PowerPoint;namespace test public partial class Form3 : Form public Form3() InitializeComponent(); System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false; / this.CheckForIllegalCrossThreadCalls string file_extend = string.Empty; ToolTip tool_showinfo = new ToolTip(); CopyFile copyfile; private void Form3_Load(object sender, EventArgs e) copyfile = new CopyFile(listBox1, listView1); private void button1_Click(object sender, EventArgs e) Thread t = new Thread(copyfile.copy); t.Start(); Thread.Sleep(5000); private void button2_Click(object sender, EventArgs e) private void button3_Click(object sender, EventArgs e) public class CopyFile public CopyFile(ListBox listBox1, ListView listView1) this.listBox1 = listBox1; this.listView1 = listView1; string dir = C:a; string d = d:a; private ListBox listBox1; private ListView listView1; /Word转a换?成pdf / / 把?Word文?件t转a换?成为aPDF格?式?文?件t / / 源文?件t路径? / 目?标文?件t路径? / true=转a换?成功| private bool DOCConvertToPDF(string sourcePath, string targetPath) bool result = false; Microsoft.Office.Interop.Word.WdExportFormat exportFormat = Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF; object paramMissing = Type.Missing; Word.ApplicationClass wordApplication = new Microsoft.Office.Interop.Word.ApplicationClass(); Microsoft.Office.Interop.Word.Document wordDocument = null; try object paramSourceDocPath = sourcePath; string paramExportFilePath = targetPath; Microsoft.Office.Interop.Word.WdExportFormat paramExportFormat = exportFormat; bool paramOpenAfterExport = false; Word.WdExportOptimizeFor paramExportOptimizeFor = Word.WdExportOptimizeFor.wdExportOptimizeForPrint; Word.WdExportRange paramExportRange = Word.WdExportRange.wdExportAllDocument; int paramStartPage = 0; int paramEndPage = 0; Word.WdExportItem paramExportItem = Word.WdExportItem.wdExportDocumentContent; bool paramIncludeDocProps = true; bool paramKeepIRM = true; Word.WdExportCreateBookmarks paramCreateBookmarks = Word.WdExportCreateBookmarks.wdExportCreateWordBookmarks; bool paramDocStructureTags = true; bool paramBitmapMissingFonts = true; bool paramUseISO19005_1 = false; wordDocument = wordApplication.Documents.Open( ref paramSourceDocPath, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing); if (wordDocument != null) wordDocument.ExportAsFixedFormat(paramExportFilePath, paramExportFormat, paramOpenAfterExport, paramExportOptimizeFor, paramExportRange, paramStartPage, paramEndPage, paramExportItem, paramIncludeDocProps, paramKeepIRM, paramCreateBookmarks, paramDocStructureTags, paramBitmapMissingFonts, paramUseISO19005_1, ref paramMissing); 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(失败); result = false; finally if (wordDocument != null) wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing); wordDocument = null; if (wordApplication != null) wordApplication.Quit(ref paramMissing, ref paramMissing, ref paramMissing); wordApplication = null; GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); return result; / / 把?Excel文?件t转a换?成PDF格?式?文?件t / / 源文?件t路径? / 目?标文?件t路径? / true=转a换?成功| private bool XLSConvertToPDF(string sourcePath, string targetPath) bool result = false; Microsoft.Office.Interop.Excel.XlFixedFormatType targetType = Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF; object missing = Type.Missing; Microsoft.Office.Interop.Excel.ApplicationClass application = null; Microsoft.Office.Interop.Excel.Workbook workBook = null; try application = new Microsoft.Office.Interop.Excel.ApplicationClass(); object target = targetPath; object type = targetType; workBook = application.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, missing); 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(失败); result = false; finally if (workBook != null) workBook.Close(true, missing, missing); workBook = null; if (application != null) application.Quit(); application = null; GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); return result; / / 把?PowerPoing文?件t转a换?成PDF格?式?文?件t / / 源文?件t路径? / 目?标文?件t路径? / true=转a换?成功| private bool PPTConvertToPDF(string sourcePath, string targetPath) bool result; Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType targetFileType = Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPDF; object missing = Type.Missing; Microsoft.Office.Interop.PowerPoint.ApplicationClass application = null; Microsoft.Office.Interop.PowerPoint.Presentation persentation = null; try application = new Microsoft.Office.Interop.PowerPoint.ApplicationClass(); persentation = application.Presentations.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(失败); result = false; finally if (persentation != null) persentation.Close(); persentation = null; if
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年消防操作员考试题及答案
- 备战2026年高考英语考试易错题(新高考)易错点19 读后续写(解析版)
- 风险传递路径解析方法-洞察与解读
- 2025年卫生成果官岗位招聘面试参考题库及参考答案
- 2025年活动策划总监招聘面试参考题库及答案
- 2025年线上客服专员岗位招聘面试参考题库及参考答案
- 2025年企业风险评估师岗位招聘面试参考题库及参考答案
- 网红巧克力测试题及答案
- 2025年护理助手新冠题库及答案
- 2025年保险销售员岗位招聘面试参考题库及参考答案
- 2025年病历书写基本规范培训考核试题(+答案解析)
- 集装箱式预制舱施工方案
- 现场交叉作业安全管理课件
- 110kV变电站设计探讨
- 2025-2026学年人教版高一化学上学期期中模拟卷(原卷及解析)
- 《军用关键软硬件自主可控产品名录》(2025年v1版)
- 给水设备调试及维护方案
- 2025年行政管理执法资格及综合法律法规知识考试题库(附含答案)
- 开放大学电大本科《古代汉语专题》2025年期末试题及答案
- 集团电力建设业务安全生产“十四五”总结暨“十五五”规划报告范文
- 2024年贵州综合评标专家库评标专家考试经典试题及答案
评论
0/150
提交评论