zoukankan      html  css  js  c++  java
  • [WPF]读取word文档


    //将word转换成xps
    private XpsDocument ConvertWordToXPS(string wordDocName) { FileInfo fi = new FileInfo(wordDocName); XpsDocument result = null; string xpsDocName = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache), fi.Name); xpsDocName = xpsDocName.Replace(".docx", ".xps").Replace(".doc", ".xps"); Microsoft.Office.Interop.Word.Application wordApplication = new Microsoft.Office.Interop.Word.Application(); try { if (!File.Exists(xpsDocName)) { wordApplication.Documents.Add(wordDocName); Microsoft.Office.Interop.Word.Document doc = wordApplication.ActiveDocument; doc.ExportAsFixedFormat(xpsDocName, WdExportFormat.wdExportFormatXPS, false, WdExportOptimizeFor.wdExportOptimizeForPrint, WdExportRange.wdExportAllDocument, 0, 0, WdExportItem.wdExportDocumentContent, true, true, WdExportCreateBookmarks.wdExportCreateHeadingBookmarks, true, true, false, Type.Missing); result = new XpsDocument(xpsDocName, System.IO.FileAccess.Read); } if (File.Exists(xpsDocName)) { result = new XpsDocument(xpsDocName, FileAccess.Read); } } catch (Exception ex) { string error = ex.Message; wordApplication.Quit(WdSaveOptions.wdDoNotSaveChanges); } wordApplication.Quit(WdSaveOptions.wdDoNotSaveChanges); return result; }
    //页面调用

    DocumentViewer docViewer = new DocumentViewer();
    docViewer.Document = new XpsDocument(("地址参数"+ ".xps"), System.IO.FileAccess.Read).GetFixedDocumentSequence();

    docViewer.FitToWidth();

     
  • 相关阅读:
    Oozie简介
    ASP.NET Redis 开发
    迁移到 Express 4.x
    vim文本编辑器
    【Shell常用命令二】管道符 通配符
    【Shell常用命令一】echo bash alias history 输出重定向 快捷键
    【linux学习笔记八】常用命令
    【linux学习笔记七】关机重启命令
    【linux学习笔记六】压缩 解压缩命令
    【linux学习笔记五】帮助命令
  • 原文地址:https://www.cnblogs.com/wdd812674802/p/10947596.html
Copyright © 2011-2022 走看看