書式設定なしでExcelワークシートを自動エクスポート

書式設定なしでExcelワークシートを自動エクスポート

それぞれにシート数が異なっている Excel ファイルが数百個あります。各シートを CSV としてエクスポートする必要があります (「各」、「セル」、「内の」、「引用符」を付けるのが望ましいですが、必須ではありません)。理想的には、どの列も日付として再フォーマットされないようにします。

これを自動化する方法はありますか? PowerShell で何かできないかと調べたのですが、Excel に関して私が見たものはすべて COM オブジェクトに関係しており、私は COM オブジェクトに詳しくなく、残念ながら今は学習する時間もないので、避けようとしています。

答え1

MS powershellgallery.com のモジュールの 1 つを使用します...

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 (できれば「各」、「セル」、「内」、「引用符」を使用...')

...Export-Csvコマンドレットを使用すると、設計上これが実行されます

# 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

ウェブ検索すると、次のような例が表示されます。

「PowerShell で Excel を CSV に変換する」

ヒット例:

PowerShell スクリプトから Excel ファイルを CSV に変換する

ImportExcel モジュールの使用: 初見

Import-Excel -Path .\ddm.xlsx -WorksheetName 'DDM Data' | 
Tee-Object -Variable xlData

関連情報