1

I have this Excel file:

enter image description here

(You can see the cell names (or codes) signed with the red color).

I search a way to read the data on this Excel template that, in future, will be in these cells. I think of to use the cell code, but I don't know how. I had tried in this way:

public partial class CaricaDocumento : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Upload();
    }

    protected void Upload()
    {
        FileStream stream = File.Open("C:\\TEMPLATE_P6.xlsx", FileMode.Open, FileAccess.Read);

        // Reading from a OpenXml Excel file (2007 format; *.xlsx)
        IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);

        // Data Reader methods
        while (excelReader.Read())
        {
            int i = excelReader.GetOrdinal("AO10"); // doesn't works: throw a System.NotSupportedException
            var s = excelReader.GetValue(i);
            System.Console.WriteLine(s.ToString());
        }

        //Free resources
        excelReader.Close();
    }

}

I didn't find nothing simple to use. I have read about some 3rd-party libraries, but I prefer to avoid using them (if it is possible).

Gioce90
  • 554
  • 2
  • 10
  • 31

2 Answers2

0

you can read this artical http://www.codeproject.com/Tips/696864/Working-with-Excel-Using-Csharp and download porject (if you are signed in)

or read it, if you want to use openxml.dll open xml excel read cell value

Community
  • 1
  • 1
Bushuev
  • 557
  • 1
  • 10
  • 29
0

I have found the correct solution, in this discussion: Reading Excel in c# where some columns are empty

Is complete and resolve many issues.

Community
  • 1
  • 1
Gioce90
  • 554
  • 2
  • 10
  • 31