How to display list of tabs in an Excel spreadsheet using C#?

Posted on 2018-02-09
Medium Priority
Last Modified: 2018-02-10
I have a client who sends me spreadsheets full of customer data. Up until now it was always one spreadsheet per customer. Now they are putting each of their  customer's data on a  separate tab inside one spreadsheet. How do I now update my C# code to give them a selection box for each tab and then read the data in the tab chosen?
Question by:rwheeler23
  • 2
  • 2
LVL 36

Accepted Solution

Miguel Oz earned 2000 total points
ID: 42464327
Use Microsoft.Office.Interop.Excel: (This library depends on which version of Excel you are using)

using Excel = Microsoft.Office.Interop.Excel;

Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"Book1.xlsx");
foreach (Excel.Worksheet displayWorksheet in xlWorkbook.Worksheets)

Open in new window


Author Comment

ID: 42464329
Thanks. They have a mixture of Excel 2010 and 2013. I will tell them to always use the same one. I suppose a logical follow-up question would be is a way to determine which version they are using?
LVL 36

Expert Comment

by:Miguel Oz
ID: 42464334
No the interop works OK with older versions as well, just add the 2013 assembly to your project and you should  be fine

Author Closing Comment

ID: 42464574

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Join & Write a Comment

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

592 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question