C #. Net:excel npoi Import and export operation Tutorial read Excel file information and output

Source: Internet
Author: User

C #. Net:excel npoi Import and export operation Tutorial read Excel file information and output


Using Npoi. HSSF. Usermodel;
Using Npoi. Ss. Usermodel;
Using System;
Using System.Collections.Generic;
Using System.IO;


Create a file Stream object
using (FileStream filesrc = File.openread (@ "C:\Users\Administrator\Desktop\123.xls"))
        {
Workbook objects Get Excel content
Iworkbook workbook = new Hssfworkbook (FILESRC);

for (int i = 0; i < workbook. Numberofsheets; i++)
            {
Get a worksheet in a workbook
isheet sheet = workbook. Getsheetat (i);
Console.WriteLine (sheet. SheetName);
for (int r = 0; r <= sheet. Lastrownum; r++)
                {
Get information for each table
IRow row = sheet. GetRow (r);
for (int c = 0; c < row. Lastcellnum; C + +)
                    {
Get information for each cell in each row
Icell cell = row. Getcell (c);
Console.WriteLine (cell.  ToString () + "| ");
                    }
                }

            }

———————— Share End ————————

C #. Net:excel npoi Import and export operation Tutorial read Excel file information and output

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.