none
Add new Worksheet c# (doubts) RRS feed

  • Question

  • Hi everyone!

    I'm working with C# and Excel for the first time ... And I would like to know how can I add a new worksheet in a Workbook. I have been reading some posts but none works for me so I'm going to post my code.

    Microsoft.Office.Interop.Excel.Application Excel = new Microsoft.Office.Interop.Excel.Application();
    Excel.Workbooks.Add();
    Microsoft.Office.Interop.Excel._Worksheet Worksheet = Excel.ActiveSheet;

    And with this code I am working with my only Sheet, but now I want to add another one with MMPP name but I can't ... After this I would like to make a dynamic table in the Worksheet MMPP. Can you help me a little?

    Thank you for read and try to help!

    Thursday, November 21, 2019 3:49 PM

All replies

  • You are almost correct with your code:

    Try this:

    Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook xlWorkBook = excel.Workbooks.Open("your_file_name_and_url.xlsx"); xlWorkBook.Worksheets.Add();


    Robert McArthur

    • Proposed as answer by Robert McArthur Thursday, November 28, 2019 4:02 AM
    Saturday, November 23, 2019 5:51 AM