公交车上荫蒂添的好舒服的电影-公用玩物(np双xing总受)-公用小荡货芊芊-公与妇仑乱hd-攻把受做哭边走边肉楼梯play-古装一级淫片a免费播放口

LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發文檔 其他文檔  
 
網站管理員

C# 將doc轉換為docx(需Office的Word包支持)

admin
2023年12月30日 0:16 本文熱度 1246

因為從事行業原因長期跟遠古OA平臺打交道,導出來的文檔都是DOC格式,遠古格式操作起來很多類不兼容,非常折磨。所以想研究一個量化的轉化工具。本人沒從事本專業,學藝不精,雖然也能通過PY寫簡單的轉換器,但還是C#對Windows兼容性更好,而且性能非常不錯,至少我是非常喜歡,現在市面上的代碼存在轉化對象錯誤,一個大哥寫了個就錯了一個對象名的轉化工具被營銷號各種抄襲導致根本查不到正確的相關代碼,以下我的代碼借鑒于這位老哥的項目,由于這位老哥被抄了太多不知道到底是誰原創,所以不在此列出。

直接上代碼:

// 轉化類

// pathinfo 選擇文件夾位置

// file 對象名

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);

            //以下參數控制轉換類型,網上查到的全是錯誤的,是doc類型

            object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatXMLDocument;

            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);

 

        }

//調用實例

private void button1_Click(object sender, EventArgs e)

        {

            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)

            {

 

                this.txtDocPaths.Text = folderBrowserDialog1.SelectedPath;

               

            }

 

            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());

                }

            }

        }

//using

using Microsoft.CodeAnalysis;

using Microsoft.Office.Interop.Word;

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.IO;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

電腦里沒有原生office的在NuGet里安裝word包

有原生word的在引用里引用
懶人版C#項目:https://download.csdn.net/download/Jiangsinan_/84995190
整個項目包我都包上了,VS19直接能打開。


該文章在 2023/12/30 0:25:25 編輯過
關鍵字查詢
相關文章
正在查詢...
點晴ERP是一款針對中小制造業的專業生產管理軟件系統,系統成熟度和易用性得到了國內大量中小企業的青睞。
點晴PMS碼頭管理系統主要針對港口碼頭集裝箱與散貨日常運作、調度、堆場、車隊、財務費用、相關報表等業務管理,結合碼頭的業務特點,圍繞調度、堆場作業而開發的。集技術的先進性、管理的有效性于一體,是物流碼頭及其他港口類企業的高效ERP管理信息系統。
點晴WMS倉儲管理系統提供了貨物產品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質期管理,貨位管理,庫位管理,生產管理,WMS管理系統,標簽打印,條形碼,二維碼管理,批號管理軟件。
點晴免費OA是一款軟件和通用服務都免費,不限功能、不限時間、不限用戶的免費OA協同辦公管理系統。
Copyright 2010-2025 ClickSun All Rights Reserved

主站蜘蛛池模板: 国产女人喷浆 | 2025国产精品极品色在线 | 99久久精品日本一区二区免 | 精品国产日韩亚洲一区二区 | 国产大片大全免费看软件下 | 国产高清中文无码在线视频 | 国产一区二区视频在线 | 国产高清在线精品一区小说 | 国产亚洲高质量一路线二路线 | 国产激情视频在线 | 国产精品成人一区无码 | 国产无码丝袜 | 国模无码一区二区 | 国产av一区二区三区久久 | 国产亚洲一区二区三区视频网站 | 高清亚洲日韩欧洲不卡在线3d | 国产欧美日韩综合精品二区久久 | 99久久久国产精品免费播放器 | 国产无码少妇影视 | 国产午夜亚洲精品午夜鲁丝片 | 国产午夜福利在线观看视频 | 91午夜在线 | 国产午夜福利一区视频 | 国产精品无码永久免费不卡 | 国产一级内谢a级高清毛片古装 | 国产综合精品一区二区 | 国产肥老上视频 | 国产一区二区三区在线免费观看 | 18处破外女出血在线 | 国产成人精品无码一区二区三区 | 国产日韩精品一区二区在线观 | aⅴ无码一线天在 | 激情国产精品一区二区 | 国产午夜精品久久理论片小 | 国产成人精品三上悠亚久久 | 91麻豆成人精品国产免费网站 | 国产精品午夜一区二区 | 国产熟女 | 99亚洲中文字幕精品一区二区 | 国产午夜麻豆影院在线观看 | 精品少妇无遮挡毛片视频软件 |