
我有數百個 Excel 文件,每個文件中的工作表數量各不相同。我需要將每張工作表匯出為CSV(最好使用“每個”、“單元格”、“in”、“引號”,但不是必需的),理想情況下沒有任何列被重新格式化為日期。
有沒有辦法自動執行此操作?我考慮使用 PowerShell 做一些事情,但我看到的有關 Excel 的所有內容都涉及 COM 對象,我試圖避免這些對象,因為我不熟悉它們,而且不幸的是現在沒有時間學習機會。
答案1
使用 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.
#>
...讀取檔案。
至於這個…
'...CSV(最好有「each」、「cell」、「in」、「quotes」...'
....使用 Export-Csv cmdlet 是有意這樣做的
# 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
網路搜尋會向您展示範例:
點擊範例:
Import-Excel -Path .\ddm.xlsx -WorksheetName 'DDM Data' |
Tee-Object -Variable xlData