Print pdf files from folder, matching the numbers in the Excel column

Hi folks,

I need to write the script performs the following tasks:

there is a column of numbers in Excel . Column's length is not known beforehand. On the other hand there is the folder that contains the files of invoices in PDF format. it is necessary to print all existing files matching the numbers in the column and for those numbers that do not have corresponding the  pdf files, to display a message: "In the folder does not corresponding invoice number"
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Joe Winograd, Fellow&MVEDeveloperCommented:
Is the entire file name just the invoice number or are there other characters in the file name? For example, if a cell in the Excel spreadsheet is:


is the file name just


or could it be

Invoice 123456.pdf

or inv_123456_20141109.pdf

or whatever? Regards, Joe
nesher13Author Commented:
cell in the Excel spreadsheet is:


the file name just

Joe Winograd, Fellow&MVEDeveloperCommented:
A few more questions:

(1) Is the Excel spreadsheet in the same folder as the PDF files?

(2) Do you already have a program installed that can print a PDF file via the command line? I recommend it to have a "quiet/no-UI" option so that the program doesn't appear for each file that is printed.

(3) Do you want to print to the default printer or be able to specify (by name) which printer to use?

(4) I see that your Tags and Topics for this question include PowerShell. Does the script have to be written in PowerShell or can it be in another scripting language?

Regards, Joe
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

nesher13Author Commented:
Joe Winograd

(1) no

(2)  I'm going to print pdf using command: Start-Process -FilePath $filepath :\Invoice.pdf"

(3)  I want to print to the default printer

(4)  The script have to be written in PowerShell

Regards, nesher13
Joe Winograd, Fellow&MVEDeveloperCommented:
Sorry — if it must be in PowerShell, I can't help you. Regards, Joe
nesher13Author Commented:
the question is no longer relevant
Joe Winograd, Fellow&MVEDeveloperCommented:
nesher13Author Commented:
The is working script:
$ex = New-Object -ComObject Excel.Application
$ex.Visible = 1
$wb = $ex.Workbooks.Open("C:\Users\dov143\Desktop\Eli-column-new.xlsx")
$ws = $wb.Worksheets.Item(1)

$result = @()

[int]$rmax = $ws.Range("G65536").End(-4162).Row
$ws.Range("G1:G$rmax") | Where {$_.Value2} | Foreach {
	$col = $_.Column+1
	$row = $_.Row
	$val = $ws.Cells.Item($row,$col)
	$result += [pscustomobject]@{
		Invoices = $_.Value2
		Values = $val.Value2
$result | Where {!$_.Values} | Foreach {Start-Process -FilePath "s:\Invoices-SD-from-documentum\0070\$($_.Invoices).pdf" –Verb Print}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nesher13Author Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for nesher13's comment #a40466173

for the following reason:

the script is combination This script is a combination of data foundув from the Internet
Joe Winograd, Fellow&MVEDeveloperCommented:
I know very little about PowerShell, but my programming background in other languages makes me wonder where that code displays the message "In the folder does not corresponding invoice number" for those numbers that do not have corresponding PDF files. I'd like to understand this. Thanks, Joe
nesher13Author Commented:
I want to close the question
Joe Winograd, Fellow&MVEDeveloperCommented:
That's fine. I did not object to your closing the question. I simply made another post in the hopes of understanding how that script solves the question you asked.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.