none
three datatables exported to excell RRS feed

  • Question

  • I have three datatables - I wish to

    create a worksheet

    export each table to a seperate sheet.

    Can anyone advise me on how to do this - many thanks in advance

    • Moved by CoolDadTx Tuesday, October 13, 2015 5:59 PM Office related
    Tuesday, October 13, 2015 10:48 AM

Answers

All replies

  • There are two ways to make a excel file from C# code.

    1. If you only need to support .xlsx, you can use OpenXML Framework. Or ZipArchive and XMLWriter classes. No other requirements exist but there are some clases build around the Framework to make using it easier.

    2. If you also need to support the old .xls, things get trickier. You need to use the old Office COM interop. Wich requires working with COM, needs office installed and does not work from services or webservers (no interactive session).
    As we always had this, there was never a need to make any real stand alone library for this work in .NET.

    Naturally option 1 is preferable.

    Tuesday, October 13, 2015 1:31 PM
  • Can you give me an example to work thru using option 1.

    many thanks in advance

    Tuesday, October 13, 2015 3:36 PM
  • Can you give me an example to work thru using option 1.

    many thanks in advance

    http://blogs.msdn.com/b/chrisrae/archive/2011/08/18/creating-a-simple-xlsx-from-scratch-using-the-open-xml-sdk.aspx
    • Marked as answer by CanAnn Tuesday, October 13, 2015 7:31 PM
    Tuesday, October 13, 2015 4:09 PM
  • sorry that will not work for me.

    but thanks anyway.

    • Marked as answer by CanAnn Tuesday, October 13, 2015 7:31 PM
    • Unmarked as answer by CanAnn Tuesday, October 13, 2015 7:31 PM
    Tuesday, October 13, 2015 7:31 PM
  • Hi,

    We can get the recordset object via DAO/ADO from the database and using Range.CopyFromRecordset to copy it into worksheet.

    Here are some helpful links for your reference:
    Recordset Object (DAO)

    Range.CopyFromRecordset Method

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, October 14, 2015 2:08 AM
    Moderator
  • sorry that will not work for me.

    but thanks anyway.

    How about following this way to export datatable to Excel sheet in #c
    Thursday, October 15, 2015 3:21 AM