Please note that VisualCron support is not actively monitoring this community forum. Please use our contact page for contacting the VisualCron support directly.


Xander Meadow
2022-04-22T14:44:35Z
Hello,

I'm fairly new to Visual Cron and am hoping this is something that is possible. I've got an Excel file that that has a couple of worksheets in it. I was wondering if it is possible to print one of the worksheets to a PDF via Visual Cron? I was thinking the task would have some way of setting the input Excel file, the sheet to print and then the destination PDF file name. Does such a thing exist in Visual Cron, and if so what task should I use? Thank you very much.
Sponsor
Forum information
Michael Fjellström
2022-04-29T15:24:18Z
Originally Posted by: Xander Meadow 

Hello,

I'm fairly new to Visual Cron and am hoping this is something that is possible. I've got an Excel file that that has a couple of worksheets in it. I was wondering if it is possible to print one of the worksheets to a PDF via Visual Cron? I was thinking the task would have some way of setting the input Excel file, the sheet to print and then the destination PDF file name. Does such a thing exist in Visual Cron, and if so what task should I use? Thank you very much.



Hi Xander,

We do have the Excel - create task which could create a file based on an output/sheet etc. Then we have the PDF tasks (PDF convert in particular) where you can convert images or txt files among many others to a PDF file. Would that be what you're looking for or did you mean something else?
Xander Meadow
2022-07-15T17:26:39Z
Hi,

I think that would work but I was hoping to do things in one quick step. I ended up writing this PowerShell script which takes in a few parameters and will produce a PDF directly from an Excel file in one step. If someone else is running into the same problem, please feel free to use/modify as needed.

param (
    [string]$FolderPath,
    [string]$ExcelFile,
    [string]$ExcelSheet
)

################################################
#Validate parameters

if ($FolderPath.Length -eq 0) {
  Write-Host("FolderPath is a required parameter. Set it to the path of the input Excel file.  This is the same folder where the resulting PDF file will be created.")
}

if ($ExcelFile.Length -eq 0) {
  Write-Host("ExcelFile is a required parameter. Set it to the name of the Excel file you wish to print to PDF.")
}

if ($ExcelSheet.Length -eq 0) {
  Write-Host("ExcelSheet is a required parameter.  Set to the sheet, or sheets you wish to print to PDF.  The sheet list can be comma, pipe or semi-colon delimited.  Each sheet will be printed as it's own PDF.")
}

if (($ExcelFile.Length -eq 0) -or ($FolderPath.Length -eq 0) -or ($ExcelSheet.Length -eq 0)){
    Exit
}

if (-not(Test-Path($FolderPath +"\" +$ExcelFile))) {
    Write-Host("The source Excel file: " + $FolderPath +"\" +$ExcelFile + " does not exist.  Please check the path and try again.")
    Exit
}
###############################
$path = $FolderPath
$sheetNames = @()

#default to a comma separated list
$delimiter = ","

#For the sheet list, check comma delimiters
if ($ExcelSheet.IndexOfAny(",") -ge 0) {
    $delimiter = ","
}
elseif ($ExcelSheet.IndexOfAny("|") -ge 0) {
    $delimiter = "|"
}
elseif ($ExcelSheet.IndexOfAny(";") -ge 0) {
    $delimiter = ";"
}

#Trim any spaces in the delimited sheet list
foreach ($sheet in $ExcelSheet.Split($delimiter)){
    $sheetNames += $sheet.Trim()
}


$xlFixedFormat = "Microsoft.Office.Interop.Excel.xlFixedFormatType" -as [type]
$excelFiles = Get-ChildItem -Path $path -Name $ExcelFile
$objExcel = New-Object -ComObject excel.application
$objExcel.visible = $false

foreach($wb in $excelFiles) {
  $excelpath = Join-Path -Path $path $wb
  $workbook = $objExcel.workbooks.open($excelpath)

  foreach($worksheet in $workbook.WorkSheets) {
      #Print out the AUM Summary page
      if($sheetNames -contains $worksheet.name) {
        #Create the output file path/name
        $pdfFile = $worksheet.name + ".pdf"
        $filepath = Join-Path -Path $path $pdfFile

        #Create the PDF
        $worksheet.ExportAsFixedFormat($xlFixedFormat::xlTypePDF, $filepath)
      }
  }
  $objExcel.Workbooks.close()
}
$objExcel.Quit() 
Joey S
2022-07-25T20:40:07Z
I tried a number of combinations of reading, writing, converting and printing but none worked. It has come up for us before where this would be helpful but we could not get it to work.

I will add as a feature request
Scroll to Top