狠狠色丁香婷婷综合尤物/久久精品综合一区二区三区/中国有色金属学报/国产日韩欧美在线观看 - 国产一区二区三区四区五区tv

LOGO OA教程 ERP教程 模切知識(shí)交流 PMS教程 CRM教程 開發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

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

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

因?yàn)閺氖滦袠I(yè)原因長(zhǎng)期跟遠(yuǎn)古OA平臺(tái)打交道,導(dǎo)出來(lái)的文檔都是DOC格式,遠(yuǎn)古格式操作起來(lái)很多類不兼容,非常折磨。所以想研究一個(gè)量化的轉(zhuǎn)化工具。本人沒從事本專業(yè),學(xué)藝不精,雖然也能通過(guò)PY寫簡(jiǎn)單的轉(zhuǎn)換器,但還是C#對(duì)Windows兼容性更好,而且性能非常不錯(cuò),至少我是非常喜歡,現(xiàn)在市面上的代碼存在轉(zhuǎn)化對(duì)象錯(cuò)誤,一個(gè)大哥寫了個(gè)就錯(cuò)了一個(gè)對(duì)象名的轉(zhuǎn)化工具被營(yíng)銷號(hào)各種抄襲導(dǎo)致根本查不到正確的相關(guān)代碼,以下我的代碼借鑒于這位老哥的項(xiàng)目,由于這位老哥被抄了太多不知道到底是誰(shuí)原創(chuàng),所以不在此列出。

直接上代碼:

// 轉(zhuǎn)化類

// pathinfo 選擇文件夾位置

// file 對(duì)象名

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

            //以下參數(shù)控制轉(zhuǎn)換類型,網(wǎng)上查到的全是錯(cuò)誤的,是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);

 

        }

//調(diào)用實(shí)例

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("當(dāng)前處理的文件:{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#項(xiàng)目:https://download.csdn.net/download/Jiangsinan_/84995190
整個(gè)項(xiàng)目包我都包上了,VS19直接能打開。


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