imports Microsoft.Office.Interop.Excel
imports Microsoft.Office.Interop
-------------------------------------------------------------
''' <summary>
''' Excelファイルをpdfファイルに変換する ''' </summary> ''' <returns></returns> ''' <remarks></remarks> Private Function ConvertExcelTopdf() As Boolean Dim rtn As Boolean = False Dim xlApp As Object xlApp = CreateObject("Excel.Application") xlApp.displayAlerts = False Try Dim xlBooks As Object = xlApp.Workbooks Dim xlBook As Object = xlBooks.Open(fnex) Dim xlSheets As Object = xlBook.Sheets Dim fileNm As String = DateTime.Today.ToString("yyyyMMdd") Dim newFn As String = "C:\Temp\" & "Temp" & ".pdf" xlBook.ExportAsFixedFormat(Type:=0,_ filename:=newFn,_ Quality:=0,_ IncludeDocPropertIEs:=True,_ IgnorePrintAreas:=False,_ OpenAfterPublish:=False) xlBook.Save() 'MessageBox.Show("pdf作成しました。") If Not xlSheets Is nothing Then Try Finally System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets) End Try End If If Not xlBook Is nothing Then Try xlBook.Close() Finally System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook) End Try End If If Not xlBooks Is nothing Then Try Finally System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBooks) End Try End If rtn = True Catch ex As Exception 'errmsg = ex.Message 'Console.Writeline("ERROR! ->" & errmsg) MessageBox.Show("pdf作成中、エラー...") Finally If Not xlApp Is nothing Then Try xlApp.Quit() Finally System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp) End Try End If End Try Return rtn End Function 总结以上是内存溢出为你收集整理的vb.net 将excel文件转换为PDF文件全部内容,希望文章能够帮你解决vb.net 将excel文件转换为PDF文件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)