none
How to export Dataview and Datagridview to an excel spreadsheet? and how to modify exported data to look like other tables? RRS feed

  • Question

  • Hi, i'm finding some issue to export data to an Excel spreadsheet. I guess I'm missing some references, but i tried to use:

    Microsoft.Office.Interop.Excel.Application

    and instructions weren't recognized by Visual Studio. Is there any other way to do it??

    Thursday, October 4, 2018 11:25 PM

Answers

  • Add a reference into your project for Microsoft.Office.Interop.Excel.

    Or you can go with an alternate method if using a DataTable. This method requires a free Excel library which is installed via NuGet, see this page.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Alexanderkng Friday, October 5, 2018 3:50 AM
    Friday, October 5, 2018 12:11 AM
    Moderator

All replies

  • Add a reference into your project for Microsoft.Office.Interop.Excel.

    Or you can go with an alternate method if using a DataTable. This method requires a free Excel library which is installed via NuGet, see this page.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Alexanderkng Friday, October 5, 2018 3:50 AM
    Friday, October 5, 2018 12:11 AM
    Moderator
  • Add a reference into your project for Microsoft.Office.Interop.Excel.


    Hi Karen, thanks for taking the time to answer.

    I can't find Microsoft.Office.Interop.Excel. It's just not on my references list.

    I will check the second option, but i'd like to make my interop code work if possible. I think Microsoft.Office.Interop.Excel reference is somehow not installed on VS. How can I fix this in order to export to excel?

    Friday, October 5, 2018 12:56 AM
  • The path (use the browse button under add references) should be like the following and the bold may be different on your computer.

    C:\Program Files (x86)\Microsoft Visual Studio 14.0\Visual Studio Tools for Office\PIA\Office15\Microsoft.Office.Interop.Excel.dll

    To be honest, using Interop really in coding today should be a last resort while using libraries such as SpreadSheetLight should be considered first as they are based on Open Office XML which means no worries about ensuring memory of objects get released. Search the web for things like "VB.NET Excel hangs around in memory" where this is not the case with SpreadSheetLight or paid libraries such as Aspose or GemBox. I personally use GemBox.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, October 5, 2018 2:44 AM
    Moderator
  • C:\Program Files (x86)\Microsoft Visual Studio 14.0\Visual Studio Tools for Office\PIA\Office15\Microsoft.Office.Interop.Excel.dll


    Weird. I don't that that Path on my VS 2017... I'll take your advice and check the alternate method this weekend. 

    Thanks for the big help, Karen. I really appreciate your attention.

    Friday, October 5, 2018 3:50 AM