Operations on excel file

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of BenH BenH 3 months ago.

  • Author
    Posts
  • #53582
    Profile photo of Bindushree L
    Bindushree L
    Participant

    Hello,

    I have an excel file on which i need to do 2 operations:
    1. Check if the file is empty or not. I checked with this code

    if((Get-content "file.txt") -eq $null){"File empty"}else{"File not empty"}

    and replaced an excel instead of .txt, thought the code worked for text files it dint work for excel.
    2. The data received in the excel file is sometimes old, therefore im trying to find out whether the data is correct or old by comparing it with previous sheet(the data is appended to a new sheet of the same excel file everytime). One field has the value "date" which im using to compare.

    Im new to powershell please help me understand the logic.

    Thanks,
    Bindu

  • #53593
    Profile photo of BenH
    BenH
    Participant

    PowerShell can access and deal with Excel files in two ways. One is using the Excel application as a COM object. Francois-Xavier Cat has a great blog post on this:

    http://www.lazywinadmin.com/2014/03/powershell-read-excel-file-using-com.html

    The other way is if the document is a xlsx file. This is a standardize structured data which PowerShell is great at working with. Warren Frame wrote a handy PowerShell module around it:

    http://ramblingcookiemonster.github.io/PSExcel-Intro/

    There is Doug Finke's xlsx module as well:

You must be logged in to reply to this topic.