Excel自动更改页面布局方向和打印

我使用openxlsx包在R生成了一堆excel工作簿,每个工作簿都有一个工作表。 现在要打印这些文件,我必须打开每个文件,进入页面布局>方向>横向,然后转到文件>打印>缩放>适合所有列在一个页面,然后打印它。 它变得非常乏味,特别是当我生成超过200个Excel文件。 有什么办法可以自动化吗? 我看到的R包中没有一个似乎有办法做到这一点,我可以接受任何语言/工具。

我想说的最好的方法是logging大部分你想要的macros(方向和打印),然后使用VBA打开每个文件调用你logging的macros,然后closures文件,一旦打印。

 Sub Macro() Dim fpath As String fpath = Worksheets("Sheet1").Range("H4").Value 'I use a file that has a file path cell which helps with dealing with lots of sheets .DisplayAlerts = False .ScreenUpdating = False Workbooks.Open Filename:= _ fpath & "\" & "Test File.xlsx" Sheets("Sheet1").Select 'Call the macro at this point Windows("Test File.xlsx").Activate ActiveWorkbook.Close .DisplayAlerts = True .ScreenUpdating = True End Sub 

我testing得非常快,对我来说似乎很好。

但是可能会有一个更简单的方法来解决这个问题,但是我正是这么做的