目录

介绍

代码


介绍

虽然现在office 的版本已经很高了,而且新的word都是使用的docx格式了,但是仍然还是存在doc格式的使用情况。尤其是对于一些旧的系统,这些系统的导出格式仍然是doc格式。而如果你需要进行word文档的相关操作——如导入,那么doc格式就不是那么的友好了。曾在度娘中找了很多资料,最后还是曲线救国,使用doc转docx后在导入word内容。

代码

不多说了,直接上代码才最实在

        public void TranWordDocToDocx(string pathinfo, string file){Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();Microsoft.Office.Interop.Word.Document doc = new Microsoft.Office.Interop.Word.Document();object oMissing = System.Reflection.Missing.Value;Object ConfirmConversions = false;Object ReadOnly = false;Object AddToRecentFiles = false;Object PasswordDocument = "";Object PasswordTemplate = System.Type.Missing;Object Revert = System.Type.Missing;Object WritePasswordDocument = System.Type.Missing;Object WritePasswordTemplate = System.Type.Missing;Object Format = System.Type.Missing;Object Encoding = System.Type.Missing;Object Visible = System.Type.Missing;Object OpenAndRepair = System.Type.Missing;Object DocumentDirection = System.Type.Missing;Object NoEncodingDialog = System.Type.Missing;Object XMLTransform = System.Type.Missing;Object fileName = pathinfo + "\\" + file;doc = word.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, ref XMLTransform);DirectoryInfo directory = new DirectoryInfo(pathinfo + "\\docx");if (!directory.Exists)//不存在{directory.Create();}object path = pathinfo + "\\docx\\" + file.Substring(0, file.Length - 4);object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocumentDefault;doc.SaveAs(ref path, ref format, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);doc.Close(ref oMissing, ref oMissing, ref oMissing);word.Quit(ref oMissing, ref oMissing, ref oMissing);}

以上代码中,第一个参数pathinfo表示doc文档的文件夹路径,第二个参数file表示word文件的名称。从方法的调用上说,需要选择doc文档所在的文件夹,然后可以在此文件夹下创建(如果没有)一个新的docx文件夹,用以保存转换后的word文件。

而对于调用的方式,这里给一个dome,如下

DirectoryInfo folder = new DirectoryInfo(this.txtDocPaths.Text);
foreach (FileInfo file in folder.GetFiles("*.doc"))
{if (file.ToString().IndexOf("$") == -1){this.lblMsg.Text = string.Format("当前处理的文件:{0}", file.FullName);this.lblMsg.Refresh();TranWordDocToDocx(this.txtDocPaths.Text, file.ToString());}
}

对于界面可参考如下截图

doc转docx的核心方法,大家也可根据实际项目中的需要进行调整!

c# 将doc转换为docx相关推荐

  1. 批量doc 转换为docx 文档

    python 批量doc 转换为docx 文档 import os from win32com import client as wcdef doc_to_docx(rawpath): # doc转d ...

  2. python 在linux中把doc转换为docx格式文件(支持word97和word2003)

    借助libreoffice将doc进行格式转换 #!/usr/bin/env python # coding:utf-8 import subprocess output = subprocess.c ...

  3. Python批量转换doc为docx格式

    札记:对于IT从业人员会经常接触到各种文件,其中Word文档是最常见之一,它分为.doc和.docx两种格式.通过Python操作Word文档的第三方库有python-docx和pywin32,pyt ...

  4. DOC和DOCX有何区别?如何使用Aspose实现快速互转?

    Microsoft Word文档主要有两种类型,DOC和DOCX.可以使用C#或VB.NET以编程方式将DOCX转换为DOC,也可以将DOCX转换为DOCX.Docx厉害一点,它是被压缩过的文档,体积 ...

  5. java docx转html实例_Java实现将word转换为html的方法示例【doc与docx格式】

    Java实现将word转换为html的方法示例[doc与docx格式] 发布于 2020-6-14| 复制链接 摘记: 本文实例讲述了Java实现将word转换为html的方法.分享给大家供大家参考, ...

  6. doc转docx文件会乱吗_利用python将doc文件转换为docx

    需求:最近在研究word文档的抽取,发现python中docx库只能提取以docx结尾的文件,因此需要将doc文件转换为docx. 基础知识了解 1.什么是doc? 汉语:文档(外语全称:Docume ...

  7. 实现DOC、DOCX转换为PDF 再将PDF转换为图片

    实现DOC.DOCX转换为PDF 再将PDF转换为图片 首先导入需要的依赖 <dependency><groupId>cn.hutool</groupId>< ...

  8. Word处理控件Aspose.Words功能演示:在 Python 中将 Word DOCX 或 DOC 转换为 PDF

    Word 到PDF是最流行和执行最广泛的文档转换之一.DOCX或DOC文件在打印或共享之前会转换为 PDF 格式.在本文中,我们将在 Python 中自动将 Word 转换为 PDF.步骤和代码示例将 ...

  9. Word处理控件Aspose.Words功能演示:在 Java 中将 DOC 或 DOCX 转换为 JPG

    Aspose.Words是一种高级Word文档处理API,用于执行各种文档管理和操作任务.API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word.此外 ...

最新文章

  1. 最全的CSS浏览器兼容问题整理
  2. 3.8 matlab函数参数与变量的作用域
  3. 【Tools】Modbus Poll 9安装详解
  4. 深度学习的实用层面 —— 1.10 梯度消失与梯度爆炸
  5. Undefined symbols for architecture xxx
  6. iis configuration error
  7. matplotlib axis
  8. python编码在哪里看_python怎么换编码
  9. 任玉刚【Android开发艺术探索】读后笔记一
  10. ai的预览模式切换_ai预览快捷键是什么,Adobe Illustrator预览快捷键是什么?
  11. 市政管理学试题及答案
  12. 用u盘进不了pe计算机意外地,u盘装系统启动不了无法进入pe怎么办
  13. Word 2003的基本使用
  14. 日本CKD电磁阀、CKD、电磁阀、CKD电磁阀
  15. win11解决打开文档延迟
  16. PL2303HXD驱动
  17. 使用LaTeX的中文字体出现Package fontspec Error: The font “宋体“ cannot be found.解决方案
  18. 读书笔记之鳗鱼的旅行
  19. 什么是RCT实时时钟?(STM32中RTC时钟源)
  20. ERROR 1062 (23000): ALTER TABLE causes auto_increment resequencing, resulting in duplicate entry '1'

热门文章

  1. java 执行js selenium_如何在Selenium WebDriver Java中使用JavaScript
  2. 售票pv操作java实现_随时随地打印手机照片,佳能瞬彩PV-123体验评测
  3. php取出多维数组的所有元素,php - 获取多维数组PHP中两个元素之间的所有数组 - SO中文参考 - www.soinside.com...
  4. 抓住\留住用户的引导页长什么样?
  5. 如果你需要万圣节的图片素材来点缀你的节日活动,看这里就对了
  6. idea抽取重复方法快捷键_使用 IDEA 几分钟就重构了同事800 行quot;又臭又长quot; 的类!真香!...
  7. webpack打包后引用cdn的js_手摸手 Webpack 多入口配置实践
  8. slam十四讲第二版 pdf_先搞定SLAM,再谈如何抓住下一代互联网产业爆发点!
  9. DPDK多线程:EAL pthread和lcore Affinity(F-Stack配置文件的配置参数:lcore_mask、lcore_list)
  10. 源码完全注释:socket select