Share via


Powershell script to deal with Excel file when Excel is not installed

Question

Friday, June 28, 2019 12:46 PM

Hello,

I am using below part of script to deal with excel file where it's working when excel is installed.

Now i want use the same where excel is not installed. Is there any way to deal with excel files when excel is not installed.

Your response is very much appreciated.

$Excel = New-Object -ComObject Excel.Application

$Excel.Visible = $true

$Workbook = $Excel.Workbooks.Open($ReportTemplate)
$Sheet = $Workbook.Sheets.Item("RawData")
[Void]$Sheet.Activate()

$Excel.Workbooks.OpenText($TempReport)
$SourceSheet = $Excel.ActiveWorkbook.ActiveSheet
$TempWB = $Excel.ActiveWorkbook

Thank You,

Avis

All replies (10)

Friday, June 28, 2019 2:04 PM

You could take a look at the great Powershell Module ImportExcel by Doug Finke.

Live long and prosper!

(79,108,97,102|%{[char]$_})-join''


Friday, June 28, 2019 2:05 PM

This article should be helpful:

https://devblogs.microsoft.com/scripting/introducing-the-powershell-excel-module-2/


Friday, June 28, 2019 3:11 PM

Tried got error below . Suggest pls

PS C:\windows\system32> Install-Module -Name ImportExcel
PackageManagement\Install-Package : No match was found for the specified search criteria and module name 
'ImportExcel'. Try Get-PSRepository to see all available registered module repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1772 char:21

  • ...          $null = PackageManagement\Install-Package @PSBoundParameters
    +                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package],  
       Exception
        + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
     

PS C:\windows\system32> 


Friday, June 28, 2019 3:16 PM

Tried got error below . Suggest pls

Please do not post pictures of code or error messages. Use the code posting tool provided on the icon bar of the post editor instead (second to last icon). Thanks.

You should post the relevant code you've used and the complete according error message.

Live long and prosper!

(79,108,97,102|%{[char]$_})-join''


Friday, June 28, 2019 4:29 PM

Also carefully read the error message as it gives you instructions on what to do next.

\(ツ)_/


Friday, June 28, 2019 4:32 PM

ImportExcel works with powershell 5.0 or later version, which one are you using?


Friday, June 28, 2019 4:38 PM

ImportExcel works with powershell 5.0 or later version, which one are you using?

What does that have to do with the error. The error shows that this is PS 5.1.  The error states the exact issue and what to do next.

It is critical that anyone wishing g to use PowerShell must learn how to read the error messages.

\(ツ)_/


Friday, June 28, 2019 6:36 PM

Below the details

PS C:\windows\system32> $PSVersionTable

Name                           Value                                                                                                 
                                                                                                                            
PSVersion                      5.1.14393.2791                                                                                        
PSEdition                      Desktop                                                                                               
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                               
BuildVersion                   10.0.14393.2791                                                                                       
CLRVersion                     4.0.30319.42000                                                                                       
WSManStackVersion              3.0                                                                                                   
PSRemotingProtocolVersion      2.3                                                                                                   
SerializationVersion           1.1.0.1 


Friday, June 28, 2019 6:50 PM

Please follow the instructions in  the error message and tell us what you find.

The error already told us that you were running 5.1 on Win 2016

You have installed something that has clobbered your PSGallery provider.

\(ツ)_/


Monday, July 1, 2019 6:18 AM

Hi,

Thanks for your question.

Please refer the post discussed before.

https://social.technet.microsoft.com/Forums/ie/en-US/66d950ce-4dee-49e9-9829-f756fe1781f0/trying-to-install-importexcel-module-in-powershell?forum=winserverpowershell

Best regards,

Lee

Just do it.