![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | search string in Excel Hi! I am trying to make a PowerShell script to search a string in Excel. Excel looks like this A B ------------------- abcdv 7 zswd 2 dfergh 1 swqwer 8 1. check if $input is same as A1 then $output = 7 then exit if not check next cell A2 if $input -eq A2 then $output = 2 then exit if not check next cell A3 if $input -eq A3 then $output = 1 then exit How can I write this after enabling Excel object like: $a = New-Object -comobject Excel.Application $a.Visible = $TRUE $b = $a.Workbooks.Add() $c = $b.Worksheets.Item(1) Thanks in advance pjo |
My System Specs![]() |
| | #2 (permalink) | ||||||||||||
| Guest | Re: search string in Excel pjo wrote:
Will it be this simple? I know in the past, I've had problems with figuring out how to tell Excel to stop processing rows (when it hits the first empty row). In other words, if you have a dynamic list of rows, it becomes a bit more difficult. Have you considered whether you want to save this data in a CSV format, then you could easily import into PowerShell, and save you having to use Excel's COM object? Marco -- Microsoft MVP - Windows PowerShell http://www.microsoft.com/mvp PowerGadgets MVP http://www.powergadgets.com/mvp Blog: http://marcoshaw.blogspot.com | ||||||||||||
My System Specs![]() | |||||||||||||
| | #3 (permalink) | ||||||||||||||||||||||||
| Guest | Re: search string in Excel Thanks Marco, Excel sheet will be dynamic. So I should consider CSV. pjo "Marco Shaw [MVP]" wrote:
| ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
| | #4 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: search string in Excel How to escape "," in CSV ? The original Excel cell has "abscdf, gerfs, trf" and this is put as "abscdf, gerfs, trf" and this causes confusion to match $temp = Import-Csv d:\work\test.csv| Where-Object {$_.name -eq "abscdf, gerfs, trf"} "pjo" wrote:
| ||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||
| | #5 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: search string in Excel $temp = Import-Csv d:\work\test.csv| Where-Object {$_.name -eq "abscdf`, gerfs`, trf"} I tried "`" but did not work. "pjo" wrote:
| ||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||
| | #6 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: search string in Excel This was solved by myself. Thanks ! pjo "pjo" wrote:
| ||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||
| | #7 (permalink) | ||||||||||||
| Guest | Re: search string in Excel "pjo"
are reading these messages too, one can also get this information (using almost any Windows language) by using the free IIS's Microsoft's data parser, Log Parser 2.2 (with built-in Microsoft ChartSpace chart maker) and chart the output too! Notice: IIS does not need to be running or installed in order to use Log Parser for either data parsing or chart making. And using PowerShell: # Remove any old test chart. remove-item testChart.gif $data = @("A,B", "abcdv,7", "zswd,2", "dfergh,1" "swqwer,8") # Log Parser command line version. $data | LogParser.exe "SELECT A AS Name, TO_INT(B) AS Number FROM STDIN " -i:csv -stats ff# Log Parser command line ChartSpace version. $data | LogParser.exe "SELECT A AS Name, TO_INT(B) AS Number INTO testChart.gif FROM STDIN " -i:csv -o:chart ` -chartType:ColumnClustered ` -stats ff -view n -values n# Or if the data is in a file: $data | out-file testData.csv -encoding ascii # Did we create the CSV file? To see file, # use Log Parser's datagrid. LogParser.exe "SELECT text FROM testData.csv " ` -i:textline -stats ff -o:datagrid# For general Log Parser CSV information. LogParser.exe -h -i:csv testData.csv -headerRow n# Remove any old test chart. remove-item testChart.gif # Log Parser command line ChartSpace version. LogParser.exe "SELECT A AS Name, TO_INT(B) AS Number INTO testChart.gif FROM testData.csv " -i:csv -o:chart ` -chartType:ColumnClustered ` -stats ff -view n -values nExit Search the Internet for usage of: Microsoft's Log Parser that is fully script enabled (from the IIS group) and Microsoft's ChartSpace Charting as used within Log Parser, Excel or even stand alone scripting usage (via the Office group) Just two other PowerShell fully script enabled tools! | ||||||||||||
My System Specs![]() | |||||||||||||
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| search and replace string | Ron | PowerShell | 1 | 06-16-2008 09:29 AM |
| Can Select-String search in-use files? | Chris Harris | PowerShell | 0 | 05-01-2008 11:00 AM |
| How to search and replace text in a string | Jason Murray | PowerShell | 8 | 01-07-2008 04:29 AM |
| Re: get-eventlog search string problem | Brandon Shell [MVP] | PowerShell | 1 | 12-03-2007 05:17 PM |
| Search for string in CSV and delete line if string found in line | sherlock | PowerShell | 2 | 07-02-2007 03:42 PM |