asp.net - Reading data from Excel First Sheet - C# -


There are 2 Excel Sheets - FileA & amp; FileB

Only a sheet in the FileA contains the data & amp; No shelves hidden to make sure the name is kept Sep '.

There are 3 sheets in File B in the first one & amp; The name of 'Sheet1' is named.

To test with the file, I wrote this code and it works fine. While examining the FileA schema in the code that was encountered with FileB, I see that the 'SEP' is shown as a line. Therefore, it is written to get the name of the first letter

string firstestname = dtSchema.Rows [2] ["TABLE_NAME"]. ToString ();

But for FileB, Sheet 1 appears in the schema as the first line.

  1. Why is it different for different sheets?
  2. What should I write, so that I can always get data from the first letter with the data.

      Private Zero GetDataFromExcel () {DataSet dsExcel = null; If (true) {OleDbCommand cmdSelect = null; OleDbDataAdapter daXls = Null; OLDBConnection xlsCSV = Faucet; Datatelle dtSchema = null; {XlsCSV} Try new OleDbConnection (ExcelFileConnString); If (xlsCSV.State == ConnectionState.Closed) {xlsCSV.Open (); } DtSchema = xlsCSV.GetOleDbSchemaTable (OleDbSchemaGuid.Tables, Taps); // Screenshots dtSchema Attached if (dtSchema.Rows.Count> 0) {string FirstSheetName = dtSchema.Rows [2] ["TABLE_NAME"]. Ostring (); CmdSelect = "Select" from new OleDbCommand ("[[+ + FirstSheetName +"], xlsCSV); DaXls = New OleDbDataAdapter (); Select DaXls.SelectCommand = cmd; DsExcel = new dataset (); DaXls.Fill (dsExcel); XlsCSV.Close (); } Int count = dsExcel.Tables [0] .Rows.Count; } Hold (Exception) {} Finally {if (xlsCSV! = Null & xlsCSV.State == ConnectionState.Open} {xlsCSV.Close (); XlsCSV.Dispose (); } If (cmdSelect! = Null) {cmdSelect.Dispose (); }}}}   

    Enter image details here Enter image details here

    library ExcelDataReader. You can read Excel files in old format (.xls) and a new (.xlsx) and you can save.

    With this you do not have to install any Office component and it is very easy to use. I am using it since January 2014 and I love it. You can get it or

    If you are working with only .xlsx files and you need some more advanced, you can try the Microsoft Office Open XML SDK. This is not very easy but allows you to do anything - or almost - with Excel files.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -