I have tried three different approaches, to no avail.
First is:
$s = $presentation.Slides[$targetslide]
$tb = $s.Shapes.AddTextbox($horiz,$left,$top,$width,$height)
$tb.TextFrame.TextRange.Text = $fla
the second is:
$f0a = ''
#$f1a is text to insert
$presentation.Slides[$targetslide].Shapes[1].TextFrame.TextRange.Replace($f0a, $f1a)
and the third is:
$s = $presentation.Slides[$targetslide]
$s.Shape[1].TextFrame.TextRange.Text = $fla
Neither seem to work. Do you have any suggestions as to what I should try?
Apparently,
$f0a=$s.Shapes[5].TextFrame.TextRange.Text
$test = $s.Shapes[5].TextFrame.TextRange.Replace($f0a, $f1a)
works perfectly.
Related
I want to set the filters on an existing .xls-file by running a shell script from the command line.
powershell -c "$excelObj = New-Object -ComObject Excel.Application;$excelWorkBook = $excelObj.Workbooks.Open(\"C:\Users\Desktop\Papierkorb\Test\test2.xlsx\");$excelWorkSheet = $excelObj.WorkSheets.item(\"Sheet1\");$excelWorkSheet.activate();$headerRange = $excelWorkSheet.Range(\"A1\",\"A1\").AutoFilter() | Out-Null;$excelWorkBook.Save();$excelWorkBook.Close();$excelObj.Quit()"
I am getting an error message:
Unable to get the AutoFilter property of the Range class
At line:1 char:231
I tried several adaptions with the Range, but could not fix it.
Thanks for your help,
It is not possible to set AutoFilter on a range without data.
Try to put some text into cell "A1" in the test2.xlsx file (either using Excel, or problematically with PowerShell, example below). You can even put empty string ''.
The following works for me.
$excelObj = New-Object -ComObject Excel.Application;$excelWorkBook = $excelObj.Workbooks.Open("d:\temp\test2.xlsx");
$excelWorkSheet = $excelObj.WorkSheets.item("Sheet1");
$excelWorkSheet.activate();
$headerRange = $excelWorkSheet.Range("A5","A5") ;
$headerRange.Item(1,1) = 'Something'
$headerRange.AutoFilter() ;
#$headerRange.AutoFilter() | Out-Null;
$excelWorkBook.Save();
$excelWorkBook.Close();
$excelObj.Quit()
I have one raw input from end user in to a variable as below
javascript:DS('https://HS/v1/dev/A/Machinename/SNAPNAME','XXXXX')
I want to extract url from the above input.
I want to split the url using '/' in to seperate variables.
Input :
$DSURL = "javascript:DS('https://HS/v1/dev/A/Machinename/SNAPNAME','XXXXX')"
[regex]$regex = '(?<=https:\/\/\HS\\/v1\/dev\/A\?t=)(.*)(?=' )'
$regex.Matches($DSURL).Value
$1 = https://HS/v1/dev/A/Machinename/SNAPNAME
$2 = Machinename
$3 = SNAPNAME
But it is not working,
I think the regex used is wrong,
Please help
this uses the [uri] type accelerator to convert the uri string into a uri object. then it uses the .Segments property to grab the last two segments and put them into $Vars.
you may want to look at the various properties stored in the $UriObject variable for some other interesting info. [grin]
$DSUrl = "javascript:DS('https://HS/v1/dev/A/SpiffyDoodleServer/SomeSortOfThing','XXXXX')"
$CleanedDSU = $DSUrl.Split('(')[1].Split(',')[0].Trim("'")
$UriObject = [uri]$CleanedDSU
$MachineName = $UriObject.Segments[-2].Trim('/')
$SnapName = $UriObject.Segments[-1]
$DSUrl
$CleanedDSU
$MachineName
$SnapName
output ...
javascript:DS('https://HS/v1/dev/A/SpiffyDoodleServer/SomeSortOfThing','XXXXX')
https://HS/v1/dev/A/SpiffyDoodleServer/SomeSortOfThing
SpiffyDoodleServer
SomeSortOfThing
I have managed to pull this and it is picking the output URL properly.
$text = "javascript:DS('https://HS/v1/dev/A/Machinename/SNAPNAME','XXXXX')"
($text | Select-String -Pattern #"
(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))
"#).Matches.Value
OUTPUT:
https://HS/v1/dev/A/Machinename/SNAPNAME','XXXXX
Hope it helps.
I am a beginner in Powershell scripting and facing this problem:
I generated a set of tables in a Word document.
At the end I like to align for each table the texts in all cells of the second column vertically centered. I tried to use a code structure like:
$document.Tables | ForEach-Object {...}
However I find no way to get the hands on the individual column of each table to align the texts.
What would be a possible way?
Found no answer so far. So I ended up with the following:
$word = New-Object -ComObject word.application
$document = $word.documents.open($wordTemplatePath)
...
For ($i = 1; $i -le $document.Tables.Count; $i++) {
$a = $document.Tables.Item($i).Columns.Item(2).Select()
$objSelection = $word.Selection
$objSelection.ParagraphFormat.Alignment = "wdAlignParagraphCenter"
$objSelection.Cells.VerticalAlignment = 1
}
Works fine.
To justify the whole table you can use:
$table.Range.ParagraphFormat.Alignment=1
To do just a cell:
$table.Cell(1,1).Range.ParagraphFormat.Alignment=1
Other values are 0 left (default) and 2 right
A combination of these should have your table looking perfect.
I'm attempting to use PowerShell to pickup a CSV file, subtract value of one column from another and put it in a third, then print the CSV to default printer.
I've got everything working except the math. It imports, sets up my headers, and prints. However it doesn't seem to execute my foreach to do the math. It runs without errors though.
$hhsignscsv = Import-Csv -Header ("PLU","Description","Quantity","Price","FreqShopType","FreqShopValue","FreqShopPrice","LabelFormat","LabelQTY","SizeMeasurement","Limit") -Path hhsignsmod.csv
foreach ($hhsigns in $hhsignscsv) {
$PLU = $hhsigns.PLU
$Description = $hhsigns.Description
$Quantity = $hhsigns.Quantity
$Price = $hhsigns.Price
$FreqShopType = $hhsigns.FreqShopType
$FreqShopValue = $hhsigns.FreqShopValue
$FreqShopPrice = $hhsigns.FreqShopPrice
$LabelFormat = $hhsigns.LabelFormat
$LabelQTY = $hhsigns.LabelQTY
$SizeMeasurement = $hhsigns.SizeMeasurement
$Limit = $hhsigns.Limit
}
foreach ($hhsigns in $hhsignscsv) {
$FreqShopPrice = $Price - $FreqShopValue
}
Out-Printer -InputObject $hhsignscsv
Can anyone tell me why the Math part ($FreqShopPrice = $Price - $FreqShopValue) won't put the values into the $FreqShopPrice column? I don't get any syntax errors when debugging or running but on the print out the $FreqShopPrice is blank instead of containing the value of the subtraction.
The statement
$FreqShopPrice = $hhsigns.FreqShopPrice
copies the value of the CSV field FreqShopPrice into the variable $FreqShopPrice.
The statement
$FreqShopPrice = $Price - $FreqShopValue
updates the variable $FreqShopPrice with the difference between the variables $Price and $FreqShopValue. However, since you filled those variables in a separate loop before the current loop they contain the values from the last record from the CSV.
To actually update the field FreqShopPrice in the CSV you need to do it like this:
foreach($hhsigns in $hhsignscsv) {
$hhsigns.FreqShopPrice = $hhsigns.Price - $hhsigns.FreqShopValue
}
Remove the other loop. It serves no purpose except burning CPU cycles.
I have a folder containing 9 .htk files. I need to use "dir", and then "readhtk" in a loop to import them to MATLAB, but DIR appears to give 10 files instead of 9! here is my code:
htkfiles = dir('/Users/Desktop/Acsegment/mfcdir/*.htk');
nhtkfiles = length(htkfiles); % 10!!! It should be 9 tough!
data = cell(nhtkfiles,2);
for k = 1:nhtkfiles
b(k,1) = strcat({'/Users/Desktop/Acsegment/mfcdir/'},{htkfiles(k,1).name});
eval(['data{k,1} = readhtk(b{k,1});']);
end
When looking at the filenames in htkfiles, I have them like this:
htkfiles(1,1).name = '.htk'
htkfiles(2,1).name = 'fadg0_si1279.htk'
htkfiles(3,1).name = 'fadg0_si1909.htk'
htkfiles(4,1).name = 'fadg0_si649.htk'
htkfiles(5,1).name = 'fadg0_sx109.htk'
htkfiles(6,1).name = 'fadg0_sx19.htk'
htkfiles(7,1).name = 'fadg0_sx199.htk'
htkfiles(8,1).name = 'fadg0_sx289.htk'
htkfiles(9,1).name = 'fadg0_sx379.htk'
htkfiles(10,1).name = 'faks0_si943.htk'
Comparing to what I see in that folder, the first file is not supposed to be there! Anyone got any ideas why Im getting one extra file?
As mentioned in the comments: the dir command actually works properly, there just happens to be a hidden file.
These files starting with a dot could be removed from your list like so:
d=dir;
d(strncmp({d.name},'.',1))=[];