将Excel转换为PDF [英] Converting excel to PDF
本文介绍了将Excel转换为PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Here is the following code which used for converting excel to PDF.I need a solution for PDF to be converted as password protected below code is used for converting the excel to PDF without password.
Dim excelApplication As ApplicationClass = New ApplicationClass()
Dim excelWorkbook As Workbook = Nothing
Dim paramSourceBookPath As String = "C:\test\DDB_TEST.xlsx"
Dim paramExportFilePath As String = "C:\test\Test.pdf"
Dim paramExportFormat As XlFixedFormatType = _
XlFixedFormatType.xlTypePDF
Dim paramExportQuality As XlFixedFormatQuality = _
XlFixedFormatQuality.xlQualityStandard
Dim paramOpenAfterPublish As Boolean = False
Dim paramIncludeDocProps As Boolean = True
Dim paramIgnorePrintAreas As Boolean = True
Dim paramFromPage As Object = Type.Missing
Dim paramToPage As Object = Type.Missing
Dim executableLocation As String = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
Dim xslLocation As String = Path.Combine(executableLocation, "DDL.pdf")
Dim xslLocation1 As String = Path.Combine(executableLocation, "DDL1.pdf")
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
' Open the source workbook.
excelWorkbook = excelApplication.Workbooks.Open(paramSourceBookPath)
' Save it in the target format.
If Not excelWorkbook Is Nothing Then
excelWorkbook.ExportAsFixedFormat(paramExportFormat, _
xslLocation, paramExportQuality, _
paramIncludeDocProps, paramIgnorePrintAreas, _
paramFromPage, paramToPage, paramOpenAfterPublish)
Dim picArray As Byte() = System.IO.File.ReadAllBytes(paramExportFilePath)
' System.IO.File.WriteAllBytes("hello.pdf", picArray)
End If
Catch ex As Exception
' Respond to the error.
Finally
' Close the workbook object.
If Not excelWorkbook Is Nothing Then
excelWorkbook.Close(False)
excelWorkbook = Nothing
End If
' Quit Excel and release the ApplicationClass object.
If Not excelApplication Is Nothing Then
excelApplication.Quit()
excelApplication = Nothing
End If
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()
// EncryptPdf(xslLocation, xslLocation1, "text")
End Try
End Sub
我尝试了什么:
i试用了microsoft .interop.excel用于将excel转换为pdF而不受密码保护(安全)。
What I have tried:
i tried with microsoft.interop.excel for converting excel to pdF without password protected(secured).
推荐答案
_ Worksheet.ExportAsFixedFormat方法(Microsoft.Office.Interop.Excel) [ ^ ]没有添加密码的选项。
_Worksheet.ExportAsFixedFormat method (Microsoft.Office.Interop.Excel)[^] does not have an option to add a password.
这篇关于将Excel转换为PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文