XLSX to CSVs (general)

Source: Internet
Author: User

#Copyright (c), Bryan O ' Connell#license:http://bryanoconnell.blogspot.com/p/licenses.html#Purpose:extract all of the worksheets from a Excel file into separate files.[Cmdletbinding ()]Param([Parameter (Mandatory=$true, position=0)] [string]$filepath, [Parameter (Mandatory=$true, Position=1)] [Validateset ("CSV","txt","xls","HTML")] [string]$output _type)#-----------------------------------------------------------------------------##figures out and returns the ' XlFileFormat enumeration ' ID for the specified format.#http://msdn.microsoft.com/en-us/library/office/bb241279%28v=office.12%29.aspx#note:the code being used for ' xls ' was actually a ' text ' type, but it seemed#The best for splitting the worksheets into separate Excel files.functiongetoutputfileformatid{Param([string]$fomat _name)    $Result= 0Switch($fomat _name)    {        "CSV"{$Result= 6}        "txt"{$Result= 20}        "xls"{$Result= 21}        "HTML"{$Result= 44}        default{$Result= 51}    }       return $Result}#-----------------------------------------------------------------------------#$Excel= New-object-comobject"Excel.Application"$Excel. Visible =$false #Runs Excel in the background.$Excel. DisplayAlerts =$false #supress alert messages.$Workbook=$Excel. Workbooks.Open ($filepath)#Loop through the Workbook and extract each Worksheet#In the specified file type.if($Workbook. Worksheets.count-GT0) {Write-output"Now processing: $WorkbookName"       $FileFormat= Getoutputfileformatid ($output _type)    #Strip off the Excel extension.    $WorkbookName=$filepath -replace ". xlsx","" #Post Extension    $WorkbookName=$WorkbookName -replace ". xls","" #Pre Extension    #$Worksheet = $Workbook. Worksheets.item (1)    foreach($Worksheet inch $Workbook. Worksheets) {$ExtractedFileName=$WorkbookName+"~~"+$Worksheet. Name +"."+$output _type        $Worksheet. SaveAs ($ExtractedFileName,$FileFormat) Write-output"Created file: $ExtractedFileName"    }}#Clean up & Close the main Excel objects.$Workbook. Close ()$Excel. Quit ()

Http://bryanoconnell.blogspot.jp/2012/09/extract-worksheets-from-excel.html

XLSX to CSVs (general)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.