Parallelize, minimize time Reading number of sheets from Excel file

倾然丶 夕夏残阳落幕 提交于 2019-12-25 07:58:30

问题


I have Excel file has 4 sheets, all sheets have huge number of records around 144564 record.

In my code, fill_data method will call 4 methods, each method read one sheet. the normal time it takes now is 7.02 minutes.

fill_data ()
{
    Excel.Application ExcelApplication;
    Excel.Workbooks ExcelWorkbooks;
    Excel.Workbook ExcelWorkbook1;

    ExcelApplication = new Excel.Application();  /// ApplicationClass()
    ExcelWorkbooks = ExcelApplication.Workbooks;
    try
    {
                ExcelWorkbook1 = ExcelApplication.Workbooks.Open(fileName1, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true);
    }
    catch
    {
                return;
    }

    active1 = ExcelWorkbook1.Worksheets.get_Item(1); // students list
    active2 = ExcelWorkbook2.Worksheets.get_Item(2);
    active3 = ExcelWorkbook3.Worksheets.get_Item(3);
    active4 = ExcelWorkbook4.Worksheets.get_Item(4);

    fill_students();
    fill_instructors();
    fill_exams();
    fill_rooms();

}

 public static void fill_students(){
      Excel.Worksheet active = active1;
      //Read all Cells at Sheet
 }

I try to use the Parallel feature to make the 4 methods run in parallel, instead of explicitly call methods I use invoke at Parallel class. As the following:

fill_data ()
{
    .....
    Parallel.Invoke(
            () => fill_students(),
            () => fill_instructors(),
            () => fill_exams(),
            () => fill_rooms()
        );
}

There is no enhancement on the executing time! it was 7.12 minutes! So what is going wrong? how to minimize this time?

来源:https://stackoverflow.com/questions/39555945/parallelize-minimize-time-reading-number-of-sheets-from-excel-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!