问题
So i think ive tried everything now. Im trying to get the values from radiobuttons and checkboxes from an excel sheet. My first approach was to use the Excel Data Reader: http://exceldatareader.codeplex.com/. The cells with checkboxes render empty.
Same thing if i use OLEDB;
string filename = @"C:\\" + "uploads\\SmartAuditSheet.xls";
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + filename + ";" +
"Extended Properties=Excel 8.0;";
OleDbDataAdapter dataAdapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", connectionString);
DataSet myDataSet = new DataSet();
dataAdapter.Fill(myDataSet, "BookInfo");
DataTable dataTable = myDataSet.Tables["BookInfo"];
gv.DataSource = myDataSet;
gv.DataBind();
Help please.
回答1:
I would recommend using some 3rd-party library for that - there are several out there (free and commercial) that do NOT require Excel being installed:
OpenXML 2.0 (free library from MS) can be used to read/modify the content of an .xlsx so you can do with it what you want
EPPlus (free library) works with XLSX
some (commercial) 3rd-party libraries come with grid controls allowing you to do much more with excel files (most can do not only XLSX but XLS too) in your application (be it Winforms/WPF/ASP.NET...) like SpreadsheetGear, Aspose.Cells, Flexcel etc.
回答2:
I would suggest you try something like the following.
OLEObject ole = (OLEObject)excelWorksheet.OLEObjects("Checkbox1");
回答3:
bool state = Convert.ToBoolean(ws.OLEObjects("Checkbox1").Object.value());
来源:https://stackoverflow.com/questions/7674914/reading-excel-file-getting-checkbox-value