亚洲乱色熟女一区二区三区丝袜,天堂√中文最新版在线,亚洲精品乱码久久久久久蜜桃图片,香蕉久久久久久av成人,欧美丰满熟妇bbb久久久

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

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

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

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

直接上代碼:

// 轉(zhuǎn)化類

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

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

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#項目:https://download.csdn.net/download/Jiangsinan_/84995190
整個項目包我都包上了,VS19直接能打開。


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