c# - Interop Excel is slow -


I am writing an application to open an Excel sheet and read it

  MyApp = New Excel.Application (); MyBook = MyApp.Workbooks.Open (file name); MySheet = (Excel.Worksheet) MyBook.Sheets [1]; // clarification cast is not required here lastRow = MySheet.Cells.SpecialCells (Excel.XlCellType.xlCellTypeLastCell) .ro; MyApp.Visible = false;   

This takes approximately 6-7 seconds, is it normal with Interop Excel?

In addition to this is there a faster way to read excel?

  string [] xx = new string [last row]; {Int maxCol = endCol - startCol; for int index = 1; index & lt; = last line; index ++) (Int j = 1; j & lt; = maxcol · j ++) {try {xx [index-1] + = (MySheet.Cells [Excel, in the form of Excel] range.) .Value2.ToString () ; } Hold {} if (j! = Maxcoll) xx [index - 1] + = "|"; }} MyApp.Quit (); System.Runtime.InteropServices.Marshal.ReleaseComObject (MySheet); System.Runtime.InteropServices.Marshal.ReleaseComObject (mybook); System.Runtime.InteropServices.Marshal.ReleaseComObject (MyApp);    

This answer is only about the second part of your question. You are using a lot of categories which is not desired and actually very slow.

Read the full range first and then repeat as a result:

  var xx [,] = (MySheet.Cells ["A1", "XX100"] Excel. Range) .Value2; (Int i = 0; i & lt; xx.getLength (0); i ++) {for (int j = 0; j & lt; xx.getLength (1); j ++) {console.writeline (Xx [i, j] .toString ()); }}   

It will be very fast!

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -