
Tengo varios cientos de archivos de Excel con distintos números de hojas dentro de cada uno. Necesito exportar cada hoja como CSV (preferiblemente con "cada", "celda", "entre comillas", pero no es necesario), idealmente sin que ninguna de las columnas se vuelva a formatear como fechas.
Hay alguna manera de automatizar esto? Busqué hacer algo con PowerShell, pero todo lo que vi con respecto a Excel involucra objetos COM que estoy tratando de evitar porque no estoy familiarizado con ellos y desafortunadamente no tengo tiempo en este momento para una oportunidad de aprendizaje.
Respuesta1
Utilice uno de los módulos de MS powershellgallery.com...
Find-Module -Name '*Excel*'
# Results
<#
Version Name Repository Description
------- ---- ---------- -----------
7.1.1 ImportExcel PSGallery PowerShell module to import/export Excel spreadsheets, without Excel....
0.1.12 PSWriteExcel PSGallery Little project to create Excel files without Microsoft Excel being installed.
1.0.2 PSExcel PSGallery Work with Excel without installing Excel
20.0.7654.0 ExcelCmdlets PSGallery CData Cmdlets for Excel
20.0.7654.0 ExcelServicesCmdlets PSGallery CData Cmdlets for Excel Services
0.1.6 BitTitan.Runbooks.Excel PSGallery PowerShell module for Excel-related functions and resources used in BitTitan Runbooks
20.0.7654.0 ExcelOnlineCmdlets PSGallery CData Cmdlets for Excel Online
0.1.6 BitTitan.Runbooks.Excel.Beta PSGallery PowerShell module for Excel-related functions and resources used in BitTitan Runbooks
0.6.9 ExcelPSLib PSGallery Allow simple creation and manipulation of XLSX file
0.0.4 Excelimo PSGallery Simple project generating Excel Workbooks/Worksheets
2.1 Read-ExcelFile PSGallery PowerShell module to import Excel spreadsheets, without Excel....
0.0.4 ProductivityTools.PSImportExcelToSQL PSGallery Module takes all excel files in given directory and push the content to database.
#>
... para leer los archivos.
En cuanto a esto...
'...CSV (preferiblemente con "cada","celda","entre","comillas"...'
... utilizar el cmdlet Export-Csv hace esto por diseño
# Get specifics for a module, cmdlet, or function
(Get-Command -Name Export-Csv).Parameters
(Get-Command -Name Export-Csv).Parameters.Keys
Get-help -Name Export-Csv -Examples
Get-help -Name Export-Csv -Full
Get-help -Name Export-Csv -Online
Una búsqueda en la web le mostraría ejemplos:
Resultados de ejemplo:
Convierta un archivo de Excel a CSV desde un script de PowerShell
Import-Excel -Path .\ddm.xlsx -WorksheetName 'DDM Data' |
Tee-Object -Variable xlData