简体   繁体   中英

.NET C# - Importing Excel File - Sheet Name!

I'm using the NPOI Library to import some data from an excel sheet to my database.

One early issue I'm curious about, is typically, to begin, you would have something like this:

snippet

 using (FileStream fs = File.Open(filename, FileMode.Open, FileAccess.Read))
                {
                    HSSFWorkbook templateWorkbook = new HSSFWorkbook(fs);
                    HSSFSheet sheet = templateWorkbook.GetSheet("Sales");

My query is, what happens when the name of the worksheet is different each time, eg I plan to import sales data, and the sheets within the workbooks I receive from suppliers are titled by date.

Is there any way that you can specify GetSheet(); to just get the first sheet in the workbook?

Any pointers would be much appreciated,

thanks guys :)

Without trying it out I'd assume that you're looking for getSheetAt .

So it would be:

HSSFSheet sheet = templateWorkbook.GetSheetAt(0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM