1

My excel generation time is quite long.So i refer this for time reduction:

How to speed up dumping a DataTable into an Excel worksheet?

But, I'm not able to get what are these two variable:

string [] columnNames, string [] fieldNames in the following method.

private void RenderDataTableOnXlSheet(DataTable dt, Excel.Worksheet xlWk, string [] columnNames, string [] fieldNames)
{}

I have only Datatable and worksheet. How can I generate colomnNames and FieldNames as a string[] from this?

Community
  • 1
  • 1
bapi
  • 1,903
  • 10
  • 34
  • 59

1 Answers1

1

fieldNames:

var fieldNames = dt.Columns.Cast<DataColumn>()
                           .Select(x => x.ColumnName).ToArray();

columnNames: As far as I understand, that should be the same in the default case.

The reason for two different parameters seems to be that you might want to change the printed name of the column in the Excel file.

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
  • The downvoter is encouraged to leave a comment. Otherwise the answer can't be improved. – Daniel Hilgarth May 29 '13 at 10:31
  • With your code I'm getting fieldNames populating all the columns.I did not get what you are trying to say **"that should be the same in the default case."??**Could you please explain more on this... – bapi May 29 '13 at 11:59
  • If you want the exact column names in the Excel as column headers, you can simply use `columnNames = fieldNames`. – Daniel Hilgarth May 29 '13 at 12:02
  • The logic implemented seems good.But it can not handle if the column exceeds "Z".I'm modifying logic to handle more columns and update once done.Mean while, if any one has implemented this before can post it.Thanks. – bapi May 29 '13 at 14:04
  • Modified logic per my requirement.Now, its taking less time than previous.Thanks. – bapi May 31 '13 at 10:44