How to open a huge excel file efficiently

前端 未结 11 1000
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-30 21:29

I have a 150MB one-sheet excel file that takes about 7 minutes to open on a very powerful machine using the following:

# using python
import xlrd
wb = xlrd.open_         


        
11条回答
  •  情书的邮戳
    2021-01-30 21:47

    I'm using a Dell Precision T1700 workstation and using c# I was able to open the file and read it's contents in about 24 seconds just using standard code to open a workbook using interop services. Using references to the Microsoft Excel 15.0 Object Library here is my code.

    My using statements:

    using System.Runtime.InteropServices;
    using Excel = Microsoft.Office.Interop.Excel;
    

    Code to open and read workbook:

    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
    
            Excel.Application xlApp;
            Excel.Workbook wb;
            Excel.Worksheet ws;
    
            xlApp = new Excel.Application();
            xlApp.Visible = false;
            xlApp.ScreenUpdating = false;
    
            wb = xlApp.Workbooks.Open(@"Desired Path of workbook\Copy of BigSpreadsheet.xlsx");
    
            ws = wb.Sheets["Sheet1"];
    
            //string rng = ws.get_Range("A1").Value;
            MessageBox.Show(ws.get_Range("A1").Value);
    
            Marshal.FinalReleaseComObject(ws);
    
            wb.Close();
            Marshal.FinalReleaseComObject(wb);
    
            xlApp.Quit();
            Marshal.FinalReleaseComObject(xlApp);
    
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
    }
    

提交回复
热议问题