none
How to convert excel to pdf or word? RRS feed

  • Question

  • Hi everyone!

    I have a simulation tool which exports txt files. And I need to make a word report to show all the curves based on all the txt files. My first opinion is that copy txt into an excel template that contains all the charts to show the curves. The next step I have to use these charts to make a report. In the early time I used snap shot to get each chart as a picture and paste them in word report.

    So is there any way I can convert the excel to pdf so that I can save all the pictures in adobe or can I save all excel charts to an word? BTW I made the tool by VB.NET.

    Thank you!

    Wednesday, February 13, 2019 7:53 AM

Answers

  • Hi,

    try the code:

    Imports System.IO
    Imports System.Reflection
    Imports Microsoft.Office.Interop.Excel
    
    Public Class Form1
        Dim excelApplication As Application = New Application()
        Dim excelWorkbook As Workbook = Nothing
        Dim paramSourceBookPath As String = "D:\test.xlsx"
        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, "D:\test.pdf")
        Private Sub Form1_Load(sender As Object, e As 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)
    
                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()
            End Try
        End Sub
    End Class

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by goldenview Wednesday, February 13, 2019 12:40 PM
    Wednesday, February 13, 2019 8:54 AM
    Moderator
  • Hi, you could try Spire.XLS to convert Excel containing charts to PDF.

    Imports System
    Imports System.Collections.Generic
    Imports System.Linq
    Imports System.Text
    Imports Spire.Xls
    
    Namespace ToPDF
        Class Program
            Private Shared Sub Main(ByVal args As String())
                Dim workbook As Workbook = New Workbook()
                workbook.LoadFromFile("Sample.xlsx", ExcelVersion.Version2010)
                workbook.SaveToFile("result.pdf", Spire.Xls.FileFormat.PDF)
            End Sub
        End Class
    End Namespace


    Why is this OP allowed to post?

    Every post is spam for spire. I have reported this abuse before.

    I quess I will start spamming my product too since it seems to be allowed now.

    • Marked as answer by goldenview Tuesday, April 2, 2019 6:04 AM
    Monday, April 1, 2019 8:04 AM

All replies

  • Hi,

    try the code:

    Imports System.IO
    Imports System.Reflection
    Imports Microsoft.Office.Interop.Excel
    
    Public Class Form1
        Dim excelApplication As Application = New Application()
        Dim excelWorkbook As Workbook = Nothing
        Dim paramSourceBookPath As String = "D:\test.xlsx"
        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, "D:\test.pdf")
        Private Sub Form1_Load(sender As Object, e As 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)
    
                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()
            End Try
        End Sub
    End Class

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by goldenview Wednesday, February 13, 2019 12:40 PM
    Wednesday, February 13, 2019 8:54 AM
    Moderator
  • Hi, you could try Spire.XLS to convert Excel containing charts to PDF.

    Imports System
    Imports System.Collections.Generic
    Imports System.Linq
    Imports System.Text
    Imports Spire.Xls
    
    Namespace ToPDF
        Class Program
            Private Shared Sub Main(ByVal args As String())
                Dim workbook As Workbook = New Workbook()
                workbook.LoadFromFile("Sample.xlsx", ExcelVersion.Version2010)
                workbook.SaveToFile("result.pdf", Spire.Xls.FileFormat.PDF)
            End Sub
        End Class
    End Namespace


    Why is this OP allowed to post?

    Every post is spam for spire. I have reported this abuse before.

    I quess I will start spamming my product too since it seems to be allowed now.

    • Marked as answer by goldenview Tuesday, April 2, 2019 6:04 AM
    Monday, April 1, 2019 8:04 AM