0

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.

5
  • Will you have Excel installed on the machine? If so, have you tried MS Office Interop? Commented Oct 6, 2011 at 13:45
  • I have it, but i guess it wont work when i host the site on some webserver. Commented Oct 6, 2011 at 13:47
  • What types of controls are you using on the sheet? Commented Oct 6, 2011 at 20:31
  • @TimWilliams Checkboxes and radiobuttons Commented Oct 7, 2011 at 6:04
  • What type as in Forms controls or Activex ? Commented Oct 7, 2011 at 19:14

4 Answers 4

1

I would suggest you try something like the following.

 OLEObject ole = (OLEObject)excelWorksheet.OLEObjects("Checkbox1"); 
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0
bool state = Convert.ToBoolean(ws.OLEObjects("Checkbox1").Object.value());

Comments

0

You get the object values using OpenXML. Below Code shows how to get checkbox object values using OpenXML.

using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
public static bool GetCheckBoxValue( String filePath )
{
    bool isChecked = false;
    using (SpreadsheetDocument document = SpreadsheetDocument.Open(filePath, false))                   
    {
        WorkbookPart wbPart = document.WorkbookPart;
        // Sheet object to retrieve a reference to the first worksheet.
        Sheet theSheet = wbPart.Workbook.Descendants<Sheet>().Where(s => s.Name == "Sheet1").FirstOrDefault();
        var control = wsPart.Worksheet.Descendants<DocumentFormat.OpenXml.Spreadsheet.Control>().FirstOrDefault();
        var controlProperies = (ControlPropertiesPart)wsPart.GetPartById(control.Id);
        isChecked = controlProperies.FormControlProperties.Checked == "Checked";
    }
    return isChecked ;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.