Excel into PDF

Hi,

I would like to download excel worksheet and change it into PDF for printing.
I would like a code that captures everything on the worksheet into PDF

Thanks

@Shannon_Quek

You have an activity save excel to pdf for that please use the same

https://docs.uipath.com/activities/docs/save-as-pdf-x

Cheers

I have tried that, however, it doesnt capture my whole excel sheet.
Leaving some of the information out. Is there an alternative?

@Shannon_Quek

  1. Drag and drop the “Excel Application Scope” activity onto the workflow.
  2. In the properties panel of the “Excel Application Scope” activity, specify the path to the Excel file you want to convert.
  3. Drag and drop the “Excel Read Range” activity inside the “Excel Application Scope” activity.
  4. In the properties panel of the “Excel Read Range” activity, configure the following:
  • Input > WorkbookPath: Provide the path and file name of the Excel file.
  • Input > SheetName: Specify the name of the worksheet you want to capture.
  • Output > DataTable: Create a DataTable variable to store the data from the worksheet.
  1. Drag and drop the “Excel Close Workbook” activity after the “Excel Read Range” activity.
  2. Drag and drop the “Export to PDF” activity onto the workflow.
  3. In the properties panel of the “Export to PDF” activity, configure the following:
  • Input > SourceFilePath: Specify the path and file name of the Excel file.
  • Input > DestinationFilePath: Provide the path and file name for the PDF file you want to create.
  • Input > SheetName: Specify the name of the worksheet you want to capture.
  1. Save and run the automation.

This process will read the specified worksheet from the Excel file, close the workbook, and then export the worksheet as a PDF file.

Note: Make sure to have the UiPath.Excel.Activities and UiPath.PDF.Activities packages installed in your project to access the necessary activities.

Hi @Shannon_Quek

  1. In UiPath Studio, go to Manage Packages and install the following packages if you haven’t already:
    • UiPath.Excel.Activities
    • UiPath.PDF Activities
  2. Use the Read range activity to read the excel and store it into DataTable.
  3. Use Export DataTable to PDF activity to convert the DataTable to a PDF file.
    - Input:
    - DataTable: Specify the DataTable variable from the previous activity.
    - OutputFile: Specify the path and name for the output PDF file.
  4. Save and run the workflow.
1 Like

Hii, I have the same problem, but I cannot find Export to PDF activity, only save excel file as pdf, even though I have the right package installed. Can you help me please.

I also only find “Save Excel File as pdf”. It is working, but it does not allow me to select a sheet. Thus it is always converting everything. Any idea how to just convert 1 selected sheet.
Thanks.

Install: UiPath.Excel.Activities package
Import namespace in your project - Imports Microsoft.Office.Interop.Excel
Use - UiPath Invoke Code activity.

Define the Required Arguments:(by using Edit Arguments option)

InputExcelPath (In, String) → Full path of the Excel file.
OutputPdfPath (In, String) → Full path for the output PDF file.
SheetNameOrIndex (In, Object) → Sheet name (String) or index (Integer).
Result (Out, String) → Stores success/error message.

Code:(add the code by using Edit Code option)

’ Define Variables
Dim excelApp As Microsoft.Office.Interop.Excel.Application = Nothing
Dim excelWorkbook As Microsoft.Office.Interop.Excel.Workbook = Nothing
Dim excelSheet As Microsoft.Office.Interop.Excel.Worksheet = Nothing
Try
’ Initialize Excel Application
excelApp = New Microsoft.Office.Interop.Excel.Application
excelApp.Visible = False ’ Keep Excel in background
excelApp.ScreenUpdating = False
excelApp.DisplayAlerts = False
’ Open the Excel File
excelWorkbook = excelApp.Workbooks.Open(InputExcelPath)
’ Select the Specific Sheet (Change Sheet Name or Index as needed)
excelSheet = CType(excelWorkbook.Sheets(SheetNameOrIndex), Microsoft.Office.Interop.Excel.Worksheet)
’ Export the Selected Sheet as PDF using the full reference
excelSheet.ExportAsFixedFormat(
Type:=Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF,
Filename:=OutputPdfPath
)
’ Close Workbook
excelWorkbook.Close(False)
’ Quit Excel
excelApp.Quit()
’ Release COM Objects
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelSheet)
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelWorkbook)
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp)
’ Set Success Message
Result = “Sheet '” & SheetNameOrIndex & “’ converted to PDF successfully.”
Catch ex As Exception
’ Handle Errors
Result = "Error: " & ex.Message
Finally
’ Ensure Excel is closed properly
If Not excelWorkbook Is Nothing Then excelWorkbook.Close(False)
If Not excelApp Is Nothing Then excelApp.Quit()
’ Release COM Objects
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelSheet)
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelWorkbook)
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp)
End Try