reading excel file -> getting checkbox value

你离开我真会死。 提交于 2020-01-16 19:40:29

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!