问题描述
我只想显示Excel公式的值结果,这样如果我删除公式,公式就会应用到结果中受影响。
这就是我所拥有的:
#Create Excel Object
$ xl = New-Object -ComObject Excel.Application
$ xl.visible = $ true
$ xl.DisplayAlerts = $ false
#打开现有工作簿,名称&激活工作表
$ wb = $ xl.Workbooks.Open(" C:xxxx.csv")
$ ws = $ xl.Worksheets.Item(1)。 name =" InventoryRAW"
$ xl.Worksheets.Item(" InventoryRAW")。activate()
#delete columns
[void] $ xl.Cells.Item(1,1).EntireColumn.Delete()
[void] $ xl.Cells.Item(1,1)。 EntireColumn.Delete()
[void] $ xl.Cells.Item(1,6).EntireColumn.Delete()
[void] $ xl.Cells.Item (1,5).EntireColumn.Delete()
[void] $ xl.Cells.Item(1,3).EntireColumn.Delete()
[void] $ xl.Cells.Item(2,1).EntireRow.Delete()
[void] $ xl.Cells.Item(2,2).EntireRow.Delete()
#Excel Formula
$ SN =('=右(A2,LEN(A2)-FIND(" K" ;,A2)-1)')
$ HN =('=左(B2,LEN(B2)-FIND("v",B2)-3)')
$ xl.Cells.Item(2,5).Value2 = $ SN
$ xl.Cells.Item(2,4).Value2 = $ HN
我以为我可以做类似= $ SN.Value和= $ HN的事情。价值,但它不起作用。
任何帮助将不胜感激
谢谢,
Rob
Hi,
I'd like to display only the value result of a Excel formula, so that if I delete the cell the formula is applied to the result is not affected.
This is what I have:
#Create Excel Object
$xl = New-Object -ComObject Excel.Application
$xl.visible = $true
$xl.DisplayAlerts = $false
#Open Existing Workbook, Name & Activate Worksheet
$wb = $xl.Workbooks.Open("C:xxxx.csv")
$ws = $xl.Worksheets.Item(1).name="InventoryRAW"
$xl.Worksheets.Item("InventoryRAW").activate()
#delete columns
[void]$xl.Cells.Item(1,1).EntireColumn.Delete()
[void]$xl.Cells.Item(1,1).EntireColumn.Delete()
[void]$xl.Cells.Item(1,6).EntireColumn.Delete()
[void]$xl.Cells.Item(1,5).EntireColumn.Delete()
[void]$xl.Cells.Item(1,3).EntireColumn.Delete()
[void]$xl.Cells.Item(2,1).EntireRow.Delete()
[void]$xl.Cells.Item(2,2).EntireRow.Delete()
#Excel Formula
$SN = ('=RIGHT(A2,LEN(A2)-FIND("K",A2)-1)')
$HN = ('=LEFT(B2,LEN(B2)-FIND("v",B2)-3)')
$xl.Cells.Item(2,5).Value2 = $SN
$xl.Cells.Item(2,4).Value2 = $HN
I thought I might be able to do something like = $SN.Value and = $HN.Value but it's not working.
Any help will be greatly appreciated
Thanks,
Rob
这篇关于仅将Excel公式转换为显示值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!