0

我遇到的问题是For Each ws In xlWorkbook_.Worksheets 语句的处理时间过长。只有 7 个工作表,处理一个语句需要 23 秒。我使用的模板文件是一个 .xlsx,我之前使用 ExcelWriter 编写的所有报告都使用了一个 .xls 模板文件。这是我能看到的唯一真正的区别。使用具有相同方法的 .xls 模板,该语句将在亚秒内处理。我正在使用最新版本的 OfficeWriter (8.6.1) 和 2010 版本的 Excel。

有没有其他人遇到过这个问题,或者有另一种方法可以循环浏览工作簿中的每个工作表,这会显着加快速度?

我正在使用的代码看起来像这样:

Dim xlApp_ As ExcelApplication
Dim xlWorkbook_ As Workbook
Dim xlTemplate_ As ExcelTemplate
Dim ws As Worksheet

....
Code to initially populate the data using the ExcelTemplate
  - copies single sheet to x number of additional sheets depending on how many are needed
  - renames the datamarkers on the sheets that were added and binds the datasets to the datamarkers
  - processes the template to populate all of the sheets with data
....

xlWorkbook_ = xlApp_.Open(xlTemplate_)

For Each ws In xlWorkbook_.Worksheets
  ....
  code to change worksheet name and format various parts of the worksheet
  ....
Next
4

0 回答 0