Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-11-09
12
Medium Priority
?
117 Views
Last Modified: 2014-11-26
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"
0
Comment
Question by:nesher13
  • 6
  • 6
12 Comments
 
LVL 56

Expert Comment

by:Joe Winograd, EE MVE 2015&2016
ID: 40431346
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:

123456

is the file name just

123456.pdf

or could it be

Invoice 123456.pdf

or inv_123456_20141109.pdf

or whatever? Regards, Joe
0
 

Author Comment

by:nesher13
ID: 40431421
cell in the Excel spreadsheet is:

123456

the file name just

123456.pdf
0
 
LVL 56

Expert Comment

by:Joe Winograd, EE MVE 2015&2016
ID: 40431591
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
0
Lessons on Wi-Fi & Recommendations on KRACK

Simplicity and security can be a difficult  balance for any business to tackle. Join us on December 6th for a look at your company's biggest security gap. We will also address the most recent attack, "KRACK" and provide recommendations on how to secure your Wi-Fi network today!

 

Author Comment

by:nesher13
ID: 40431948
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
0
 
LVL 56

Expert Comment

by:Joe Winograd, EE MVE 2015&2016
ID: 40432016
Sorry — if it must be in PowerShell, I can't help you. Regards, Joe
0
 

Author Comment

by:nesher13
ID: 40466137
the question is no longer relevant
0
 
LVL 56

Expert Comment

by:Joe Winograd, EE MVE 2015&2016
ID: 40466145
Why?
0
 

Accepted Solution

by:
nesher13 earned 0 total points
ID: 40466173
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}
$ex.Quit()

Open in new window

0
 

Author Comment

by:nesher13
ID: 40466205
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
0
 
LVL 56

Expert Comment

by:Joe Winograd, EE MVE 2015&2016
ID: 40466197
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
0
 

Author Comment

by:nesher13
ID: 40466206
I want to close the question
0
 
LVL 56

Expert Comment

by:Joe Winograd, EE MVE 2015&2016
ID: 40466215
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.
0

Featured Post

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Unable to change the program that handles the scan event from a network attached Canon/Brother printer/scanner. This means you'll always have to choose which program handles this action, e.g. ControlCenter4 (in the case of a Brother).
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Loops Section Overview
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question