エクセルWPFを読みます

  ///  <要約> 
        /// ExcelドキュメントをPDF形式に変換
         ///  </要約> 
        ///  <PARAM NAME = "sourcePathは"> 元のファイルのパス</ param>の
        ///  <PARAM NAME =「TARGETPATH "> PDF保存したパスにファイル変換</ param>の
        ///  <PARAM NAME ="たtargetType「> 列挙型パラメータ</ param>の
        ///  <は> </戻り値を返します> 
        プライベート BOOL ExcelConvert(文字列 sourcePathは、文字列TARGETPATH、XlFixedFormatTypeたtargetType)
        { 
            BOOLの結果は、
             オブジェクトの欠落= Type.Missing。
            Microsoft.Office.Interop.Excel.Applicationアプリケーション = nullを
            ワークブックワークブック = nullをしてみてください
            { 
                場合(!File.Exists(TARGETPATH))
                { 
                    アプリケーション = 新しいMicrosoft.Office.Interop.Excel.Application();
                    対象ターゲット= TARGETPATH。
                    オブジェクト・タイプ= たtargetType。
                    ワークブック = application.Workbooks.Open(sourcePathは、行方不明、行方不明、行方不明、行方不明、行方不明、
                            )、行方不明行方不明、行方不明、行方不明、行方不明、行方不明、行方不明、行方不明、行方不明。

                    workBook.ExportAsFixedFormat(たtargetType、ターゲット、XlFixedFormatQuality.xlQualityStandard、、)行方不明、行方不明、行方不明、行方不明。
                    結果 = ; 
                } 
                
                { 
                    結果 = 
                } 
            } 
            キャッチ
            { 
                結果 = 
            } 
            最後に
            { 
                場合(!ブック= NULL 
                { 
                    workBook.Close(、行方不明、行方不明)。
                    ワークブック = nullを
                } 
                であれば(アプリケーション!= NULL 
                { 
                    application.Quit()。
                    アプリケーション = nullを
                } 
                GC.Collect(); 
                GC.WaitForPendingFinalizers(); 
                GC.Collect(); 
                GC.WaitForPendingFinalizers();
            } 
            戻り値の結果; 
        } 


// 页面调用
 BOOL結果= ExcelConvert(パス+ファイル名、パス+ファイル名+ " .xps " 、XlFixedFormatType.xlTypeXPS)。
                        もし(結果)
                        { 
                            DocumentViewerののdocviewer = 新しいDocumentViewerの()。
                            docViewer.Document = 新しい XpsDocument((パス+ファイル名+ " .xps " )、System.IO.FileAccess.Read).GetFixedDocumentSequence(); 

                            docViewer.FitToWidth(); 
                            grid1.Children.Add(のdocviewer); 
                            docViewer.SetValue(Grid.RowProperty、0 ); 
                            docViewer.SetValue(Grid.ColumnProperty、0 ); 
                        } 
                        
                        { 
                            Xceed.Wpf.Toolkit.MessageBox.Show(" 系统调用有误、是否安装オフィス软件" );
                        }

 

おすすめ

転載: www.cnblogs.com/wdd812674802/p/10947618.html