国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
部分Office 2007文件格式轉(zhuǎn)換為xps和pdf代碼整理
轉(zhuǎn)換功能是通過(guò)調(diào)用安裝了轉(zhuǎn)換XPS和PDF的AddIn的Office2007對(duì)象模型完成的. 代碼支持Office 2007支持的一切文件格式:
Office 2007組件
擴(kuò)展名
Word
DOC, DOCX, DOCM, DOTX, DOTM, DOT, TXT, RTP, RTF
Excel
XLS, XLSX, XLSM, XML
PowerPoint
PPT, PPTX, PPTM, POTX, PPSX, PPSM, POTM
添加對(duì)三個(gè)組件的引用:
這里使用一個(gè)枚舉類(lèi)型來(lái)來(lái)決定生成文件的類(lèi)型,包括:
其實(shí)可以使用個(gè)方法來(lái)實(shí)現(xiàn)這個(gè)功能,這里Word和Excel我使用了ExportAsFixedFormat,PowerPoint使用了SaveAs,對(duì)于Word和PowerPoint效果是一樣的。只是SaveAs支持的格式更多, 但我發(fā)現(xiàn)似乎Excel不支持SaveAs.
Word轉(zhuǎn)換代碼:
        private bool Convert(string sourcePath, string targetPath, Word.WdExportFormat exportFormat)
        
{
            bool result;
            object paramMissing = Type.Missing;
            Word.ApplicationClass wordApplication = new Word.ApplicationClass();
            Word.Document wordDocument = null;
            try
            
{
                object paramSourceDocPath = sourcePath;
                string paramExportFilePath = targetPath;
                Word.WdExportFormat paramExportFormat = exportFormat;
                bool paramOpenAfterExport = false;
                Word.WdExportOptimizeFor paramExportOptimizeFor =
                    Word.WdExportOptimizeFor.wdExportOptimizeForPrint;
                Word.WdExportRange paramExportRange = Word.WdExportRange.wdExportAllDocument;
                int paramStartPage = 0;
                int paramEndPage = 0;
                Word.WdExportItem paramExportItem = Word.WdExportItem.wdExportDocumentContent;
                bool paramIncludeDocProps = true;
                bool paramKeepIRM = true;
                Word.WdExportCreateBookmarks paramCreateBookmarks =
                    Word.WdExportCreateBookmarks.wdExportCreateWordBookmarks;
                bool paramDocStructureTags = true;
                bool paramBitmapMissingFonts = true;
                bool paramUseISO19005_1 = false;
                wordDocument = wordApplication.Documents.Open(
                    ref paramSourceDocPath, ref paramMissing, ref paramMissing,
                    ref paramMissing, ref paramMissing, ref paramMissing,
                    ref paramMissing, ref paramMissing, ref paramMissing,
                    ref paramMissing, ref paramMissing, ref paramMissing,
                    ref paramMissing, ref paramMissing, ref paramMissing,
                    ref paramMissing);
                if (wordDocument != null)
                    wordDocument.ExportAsFixedFormat(paramExportFilePath,
                        paramExportFormat, paramOpenAfterExport,
                        paramExportOptimizeFor, paramExportRange, paramStartPage,
                        paramEndPage, paramExportItem, paramIncludeDocProps,
                        paramKeepIRM, paramCreateBookmarks, paramDocStructureTags,
                        paramBitmapMissingFonts, paramUseISO19005_1,
                        ref paramMissing);
                result = true;
            }
            finally
            
{
                if (wordDocument != null)
                
{
                    wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing);
                    wordDocument = null;
                }
                if (wordApplication != null)
                
{
                    wordApplication.Quit(ref paramMissing, ref paramMissing, ref paramMissing);
                    wordApplication = null;
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            return result;
        }
Excel轉(zhuǎn)換代碼:
private bool Convert(string sourcePath, string targetPath, XlFixedFormatType targetType)
        
{
            bool result;
            object missing = Type.Missing;
            ApplicationClass application = null;
            Workbook workBook = null;
            try
            
{
                application = new ApplicationClass();
                object target = targetPath;
                object type = targetType;
                workBook = application.Workbooks.Open(sourcePath, missing, missing, missing, missing, missing,
                    missing, missing, missing, missing, missing, missing, missing, missing, missing);
                workBook.ExportAsFixedFormat(targetType, target, XlFixedFormatQuality.xlQualityStandard, true, false, missing, missing, missing, missing);
                result = true;
            }
            catch
            
{
                result = false;
            }
            finally
            
{
                if (workBook != null)
                
{
                    workBook.Close(true, missing, missing);
                    workBook = null;
                }
                if (application != null)
                
{
                    application.Quit();
                    application = null;
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            return result;
        }
PowerPoint轉(zhuǎn)換代碼:
       private bool Convert(string sourcePath, string targetPath, PpSaveAsFileType targetFileType)
        
{
            bool result;
            object missing = Type.Missing;
            ApplicationClass application = null;
            Presentation persentation = null;
            try
            
{
                application = new ApplicationClass();
                persentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
                persentation.SaveAs(targetPath, targetFileType, Microsoft.Office.Core.MsoTriState.msoTrue);
                result = true;
            }
            catch
            
{
                result = false;
            }
            finally
            
{
                if (persentation != null)
                
{
                    persentation.Close();
                    persentation = null;
                }
                if (application != null)
                
{
                    application.Quit();
                    application = null;
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            return result;
        }
感謝同事Hong的協(xié)助,把這部分功能實(shí)現(xiàn),現(xiàn)在share給大家,希望為需要的朋友節(jié)省時(shí)間.
另外瀏覽xps文件有一個(gè)不錯(cuò)的小工具XPS Viewer EP.
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶(hù)發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
類(lèi)似百度文庫(kù)在線(xiàn)預(yù)覽文檔flash版(支持word、excel、ppt、pdf)+在線(xiàn)預(yù)覽文檔html版
C#根據(jù)Word模版生成Word文件
webbrowser控件顯示word文檔
c#獲取txt,word,excel文檔內(nèi)容方法
C#編程技巧:讀取Word的方法
C#操作Word(三)
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服