仅将Excel公式转换为显示值 [英] Convert Excel Formula to Display Value only

查看:158
本文介绍了仅将Excel公式转换为显示值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我只想显示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


解决方案

要替换公式,请重新分配单元格。



xl.Cells.Item(2,5).Value2 =


xl.Cells.Item( 2,5).Value2


Value2是计算值,ti将覆盖公式。



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

解决方案

To replace a formula buy its value just reassign the cell.


xl.Cells.Item(2,5).Value2 =


xl.Cells.Item(2,5).Value2

Value2 is the calculated value and ti will overwrite the formula.


这篇关于仅将Excel公式转换为显示值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆