日韩欧美人妻无码精品白浆,www.大香蕉久久网,狠狠的日狠狠的操,日本好好热在线观看

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

【C#】Winform如何利用Aspose.Words/Cells/Slides將Office文檔Word/Excel/PowerPoint一鍵轉(zhuǎn)為PDF文件

admin
2025年2月11日 11:1 本文熱度 1158

【C#】Winform如何利用Aspose.Words/Cells/Slides將Office文檔Word/Excel/PowerPoint一鍵轉(zhuǎn)為PDF文件 

先在項(xiàng)目中添加:Aspose.Cells.dll、Aspose.Words.dll、Aspose.Slides.dll 三個(gè)dll的引用。

 

然后在代碼中引入相關(guān)組件:

using Aspose.Words;

using Aspose.Cells;

using Aspose.Slides;

然后在組件上執(zhí)行相關(guān)轉(zhuǎn)換操作:

private void txt_file_path_MouseClick(object sender, MouseEventArgs e)

{

    // 創(chuàng)建 OpenFileDialog 對(duì)象

    OpenFileDialog openFileDialog = new OpenFileDialog();


    // 設(shè)置對(duì)話框標(biāo)題

    openFileDialog.Title = "選擇一個(gè)Office文件";


    // 設(shè)置文件過(guò)濾器,允許選擇特定類型的文件

    openFileDialog.Filter = "Office文件 (*.doc;*.docx;*.xls;*.xlsx;*.ppt;*.pptx)|*.doc;*.docx;*.xls;*.xlsx;*.ppt;*.pptx";


    // 允許用戶選擇多個(gè)文件

    openFileDialog.Multiselect = false;


    // 顯示對(duì)話框并檢查用戶是否點(diǎn)擊了“確定”

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

    {

        // 獲取用戶選擇的文件路徑

        string[] selectedFiles = openFileDialog.FileNames;


        // 輸出選擇的文件路徑

        foreach (string file in selectedFiles)

        {

            txt_file_path.Text = file;

        }

        // 設(shè)置輸出PDF文件的路徑

        if (txt_file_path.Text != "")

        {

            string sourceFilePath = txt_file_path.Text;

            string targetfilepath = (Public.Left(sourceFilePath, sourceFilePath.Length - 4) + ".pdf").Replace("..", ".");

            if (File.Exists(targetfilepath))

            {

                btn_office2pdf.Enabled = false;

                txt_result.Text = "文檔“" + targetfilepath + "”已經(jīng)存在,無(wú)需轉(zhuǎn)換!";

                Console.WriteLine("文檔“" + targetfilepath + "”已經(jīng)存在,無(wú)需轉(zhuǎn)換!");

            }

            else

            {

                btn_office2pdf.Enabled = true;

            }

        }

    }

}


private void btn_office2pdf_Click(object sender, EventArgs e)

{

    string sourceFilePath = txt_file_path.Text;

    if (sourceFilePath == "")

    {

        MessageBox.Show("轉(zhuǎn)換失?。簺](méi)有選擇要轉(zhuǎn)換的文件,請(qǐng)先選擇!","系統(tǒng)提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);

        return;

    }


    //轉(zhuǎn)換Office文檔為PDF文檔

    office2pdf(sourceFilePath, 0);

}


public void office2pdf(string sourceFilePath, int alertFlag)

{

    // 檢查源文件是否存在

    if (!File.Exists(sourceFilePath))

    {

        Console.WriteLine("文檔“" + sourceFilePath + "”不存在,請(qǐng)先選擇!");

        return;

    }


    // 檢查源文件是否是指定格式

    string sourceFileExt = Public.Right(sourceFilePath, 4).ToLower();

    if (!(sourceFileExt == ".doc" || sourceFileExt == ".xls" || sourceFileExt == ".ppt" || sourceFileExt == "docx" || sourceFileExt == "xlsx" || sourceFileExt == "pptx"))

    {

        Console.WriteLine("文檔格式“" + sourceFileExt + "”錯(cuò)誤,必須為doc/xls/ppt文檔!");

        return;

    }


    // 設(shè)置輸出PDF文件的路徑

    string targetfilepath = (Public.Left(sourceFilePath, sourceFilePath.Length - 4) + ".pdf").Replace("..", ".");

    if (File.Exists(targetfilepath))

    {

        Console.WriteLine("文檔“" + targetfilepath + "”已經(jīng)存在,無(wú)需轉(zhuǎn)換!");

        return;

    }


    try

    {

        if (sourceFileExt == ".doc" || sourceFileExt == "docx")

        {

            // 讀取doc文檔

            Aspose.Words.Document doc = new Aspose.Words.Document(sourceFilePath);

            //保存為PDF文件,此處的SaveFormat支持很多種格式,如圖片,epub,rtf 等等

            doc.Save(targetfilepath, Aspose.Words.SaveFormat.Pdf);

        }

        if (sourceFileExt == ".xls" || sourceFileExt == "xlsx")

        {

            // 初始化Workbook對(duì)象

            Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(sourceFilePath);

            // 將Excel保存為PDF格式

            workbook.Save(targetfilepath, Aspose.Cells.SaveFormat.Pdf);

        }

        if (sourceFileExt == ".ppt" || sourceFileExt == "pptx")

        {

            // 加載PPT或PPTX文件

            var pres = new Presentation(sourceFilePath);

            // 保存為PDF格式

            pres.Save(targetfilepath, Aspose.Slides.Export.SaveFormat.Pdf);

        }

        Console.WriteLine("文檔“" + sourceFilePath + "”轉(zhuǎn)換為PDF文檔成功。");

    }

    catch

    {

        Console.WriteLine("文檔“" + sourceFilePath + "”轉(zhuǎn)換為PDF文檔失??!\r\n請(qǐng)檢查是否是本程序沒(méi)有當(dāng)前目錄寫入權(quán)限等。");

    }

}


該文章在 2025/2/11 17:23:47 編輯過(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è)而開(kāi)發(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

aV,一区,二区,三区| 久久无码高潮丝袜免费看| 日韩久久久成人二区| 五月天av一区二区三区| 国产女同疯狂摩擦出水| 欧美又黄又大| 国产夫妻性爱网| 三级视频中文字幕| 综合成人精品视频在线| 欧美中文一级中文| 日本人妻乱交中文字幕| 国产精品人妻无码免费| 欧美中日韩特黄片| 成人网站亚洲二区乱码| thepron国产精品亚洲| 激情涩亚洲综合一区| 东北色婷婷综合在线| 精品毛片网站| 国产一区高清无码在线观看完整版| 日韩欧美成人国产二区三区在线视频| 国产探花在线精品一区二区| 亚洲色成人网站www观看入口| 乱一紧一情一爽一二三区| 日韩中文字幕区一区一区| 中文字幕侵犯一区二区三区四区 | 国产欧美另类在线观看| 国产欧美1区2区3区| 日韩爱爱视频免费| 亚洲激情麻豆久久| 欧美欧洲在线| 国产熟妇露脸3p交换| 亚洲av第一区第一页| 一区二区三区 欧美 网| 欧洲亚洲国产大片| 亚洲成人精品福利| 99成人电影| 视频二区 中文字幕 国产| 日本无码一二三区免费| 亚洲一区午夜在线gap520综合| 半夜啪啪啪网站免费不卡| 黄片免费观看一二区地址|