0

I tried to read an SLK file with excel (office 365). The SLK file has two cells. One contains a "hard coded" value, and the other contains a formula which is "5+LC(-1)". By reading the SLK with excel it works fine and I can see the formula "5+LC(-1)"

Now, I want to do a powershell script for reading this SLK file. Here is what I have done:

$FilePath = "C:\tex33.slk"

$excel = New-Object -comobject Excel.Application
$excel.Visible = $false
$excel.Application.DisplayAlerts = $false
$workbook = $excel.Workbooks.Open($FilePath)

# Print the formula
$workbook.sheets.item(1).activate()
$WorkbookTotal=$workbook.Worksheets.item(1)
$value = $WorkbookTotal.Cells.Item(1, 2).Formula2R1C1Local
$value

$workbook.Close()

I expected to see the formula 5+LC(-1) in the variable $value. However, this variable contains the result of this formula and not the formula. Do you know why I don't see the formula in powershell while I can see it on Excel? Note also that, if I do the same thing with an xlsx file instead of the SLK file, all work as expected ($value contains the formula).

Do you think this is because I didn't install PI Software as indicated at Opening an excel file manually allows formulas to run, opening an excel file with VBScript or PowerShell or Python's win32com doesn't ? In this case I don't understand why Excel succeed to see my formula while powershell failed.

The SLK file is simple (and you can see the formula 5+RC[-1]) :

ID;PMP
F;DG0G10
B;Y1;X2
C;X1;K1
C;X2;E5+RC[-1];K6
W;N1;A1 1;C7 0 7
E

0 Answers0