Skip to content

Export data from DataSet to Microsoft Excel using windows forms

Phaniraj

Asked Apr 23, 2007, 3:51 AM EDT1 answer
Share
LinkedInX
I want to Export data from DataSet to Microsoft Excel using windows forms. This is very urgent please reply if you have any idea.

I had tried the following code, But it is throwing a fatal error saying it could not able to load
excel DLL even after adding it in reference.

Excel.ApplicationClass excel = new Excel.ApplicationClass();
Excel.Workbooks workbooks = excel.Workbooks;
Excel.Workbook workbook = workbooks.Add(true);
excel.Cells[0,0] = "TestData";
Excel.Worksheet worksheet = (Excel.Worksheet)excel.ActiveSheet;
excel.Visible = true;

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0

    you are doing it wrong.
    Use Excel.Application app = new Excel.Application();
    Sometimes there are errors when using Excel, so it would be good to insert this code at the begining:

    Excel.Application app = null;
    System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
        System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

    app = new Excel.Application();

    0