打开工作簿需要花费大量时间



我正在尝试读取一个 excel 文件(xlsm 和宏一样)一切似乎都是正确的,但不知何故代码需要花费大量时间来执行。这是我的代码:

public Map<String, ReportParameter> getParameters(String excelFileName) {
        File excelFile = new File(repo.getRepositoryPath() + File.separator + excelFileName);
        try (FileInputStream input_document = new FileInputStream(excelFile);
             XSSFWorkbook workbook = new XSSFWorkbook(input_document)) {
            XSSFSheet sheet = workbook.getSheet("parametre");
            Map<String, String> resultMap = new HashMap<>();
            Map<String, Integer> indexMap = new HashMap<>();
            int pos = 1;
            for (Row row : sheet) {
                Cell cell = row.getCell(0);
                if(cell == null) {
                    continue;
                }
                indexMap.put(cell.getStringCellValue(), pos++);
                resultMap.put(cell.getStringCellValue(), row.getCell(1).getStringCellValue());
            }
            return convertParameterTypesToReportParameters(resultMap, indexMap);
        } catch (Exception e) {
             throw new RuntimeException(e);
        }

我也尝试使用OPCPackage,但结果相同。有人可以给我建议为什么需要花费大量时间,有什么可以提高性能的吗?

试试这个:

sub test()
Dim x as long, y as int 
'all of your Dims here

Application.ScreenUpdating = False
'
'
'your code here
'
'
Application.ScreenUpdating = True
end sub

最新更新