开发者

How to most effectively automate repetitive Excel task?

I want to automate Excel using Perl to do the following task(s):

For a list of Excel .xls files, do the following:
  Open the file
  Set Format to CSV
  Save the file under the original filename and directory, but replace the extension "xls" with "csv"
  Close the file
End
开发者_高级运维

I found how to open files, even how to save them. I did not find how to change the fileformat/save as a different format. There shall be no user dialogs popping up, it should be fully automated. The Excel file list I can generate myself, a parameterized "find" or maybe "dir" should suffice.


If you are using Excel automation a great help is Excel itself. Use the VBA environment (Alt+F11) to get help for the Excel objects you want to use.

The objectbrowser (F2) is very valuable.

Workbook.SaveAs([Filename], [FileFormat], [Password], [WriteResPassword], [ReadOnlyRecommended], [CreateBackup], [AccessMode As XlSaveAsAccessMode = xlNoChange], [ConflictResolution], [AddToMru], [TextCodepage], [TextVisualLayout], [Local])

Searching for CSV in the object browser will show Excel constants with their values, since you probably cannot use these Excel constants in Perl.


See Spreadsheet::ParseExcel and xls2csv, they will help you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜