c# - More efficient way to write data table to excel? -


in wpf application, have huge data table (system.data.datatable) need write sheet in excel document. heavy part of function:

        (; < dt.rows.count; i++)         {             (int colnum = 0; colnum < dt.columns.count; colnum++)                 newsheet.cells[i + rownumber, colnum + 1] = dt.rows[i][colnum].tostring();             applyrowborderstyle(newsheet, + rownumber, dt.columns.count);         } 

dt datatable, neewsheet excel sheet write to, , applyrowborderstyle(..) adds borders cells in row. runs when data table big, might take 10 minutes or more. there way make run faster?


edit: program analyses lot of data , makes lot of sheets, , can't make user anything. must use microsoft excel. sheets table has 42 columns, number of lines changes according how data did program receive, ~500 lines. "applyrowborderstyle" make code run bit faster, doesn't meet requirements.. hope there way make run faster..

found answer! here's function iv'e wrote, , reference used: http://www.codeproject.com/articles/21519/fast-exporting-from-dataset-to-excel

private void fastdttoexcel(system.data.datatable dt, worksheet sheet, int firstrow, int firstcol, int lastrow, int lastcol)     {         range top = sheet.cells[firstrow, firstcol];         range bottom = sheet.cells[lastrow, lastcol];         range = (range)sheet.get_range(top, bottom);         string[,] arraydt = new string[dt.rows.count, dt.columns.count];         (int = 0; < dt.rows.count; i++)             (int j = 0; j < dt.columns.count; j++)                 arraydt[i, j] = dt.rows[i][j].tostring();         all.value2 = arraydt;     } 

takes less second, awesome :)


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -