alec

alec

  • NA
  • 86
  • 57.5k

Background worker with input

Dec 7 2011 11:24 AM
I have a function 

public void DataTableToExcel (DataTable DT)
        {
            Excel.Application ExcelApp = new Excel.Application();
            ExcelApp.Workbooks.Add();
            ExcelApp.Workbooks[1].Worksheets.Add();
            Excel.Worksheet wSheet = ExcelApp.Workbooks[1].Worksheets[1];


            for (int i = 1; i < DT.Columns.Count + 1; i++)
            {
                wSheet.UsedRange[1, i] = DT.Columns[i - 1].ColumnName.ToString();
            }


            wSheet.get_Range(ExcelColumnLetter(0) + "1", ExcelColumnLetter(DT.Columns.Count) + "1").Font.Bold = true;


            for (int i = 0; i < DT.Rows.Count; i++)
            {
                for (int j = 0; j < DT.Columns.Count; j++)
                {
                    wSheet.UsedRange[i + 2, j + 1] = DT.Rows[i][j].ToString();
                }
            }
            ExcelApp.Visible = true;
        }

and I want it as a backgroundworker as I want it in a different thread and to report its progress. 

How do I make a backgroundworker with an input?

Answers (2)