Jump to content

Read checkbox value embedded on excel file


dee-u

Recommended Posts

  I am using PhpSpreadsheet to read the values of an excel file and I have no problem reading the values of columns. What I am having problem with is reading a value of a checkbox found in the excel sheet, is it even possible to read a checkbox value in excel using PHP? Here is one of my attempts but it cannot find any checkbox though it is there.

     $drawingCollection = $sheet1->getDrawingCollection();

        // Check if the drawing collection is empty
        if (empty($drawingCollection)) {
            echo 'No drawing objects found in worksheet' . PHP_EOL;
        } else {
            // Loop through the drawing objects
            foreach ($drawingCollection as $drawing) {
                // Check if the drawing object is a Form Control
                if ($drawing instanceof Drawing\FormControl) {
                    // Get the cell containing the Form Control
                    $controlCell = $drawing->getCoordinates();

                    // Get the value of the Form Control
                    $value = $sheet1->getCell($controlCell)->getValue();

                    // Do something with the value
                    echo 'Control value: ' . $value . PHP_EOL;
                }
            }
        }

Thank you for any one who could provide help.

Link to comment
Share on other sites

It looks like there is no way to read the value of a checkbox in an excel sheet if it is not link to a cell. I guess I've stumbled into one of the limitations of php.

EDIT: I didn't receive any notification in my email that someone replied to my thread, is that normal? I think I've subscribed to my own thread when I created it.

Edited by dee-u
Link to comment
Share on other sites

1 hour ago, dee-u said:

It looks like there is no way to read the value of a checkbox in an excel sheet if it is not link to a cell. I guess I've stumbled into one of the limitations of php.

More like PhpSpreadsheet doesn't support something that's... well, it's weird, to put form elements into a spreadsheet. That's not what spreadsheets are for.

If you want better automation, have you considered VBA?

1 hour ago, dee-u said:

EDIT: I didn't receive any notification in my email that someone replied to my thread, is that normal? I think I've subscribed to my own thread when I created it.

Subscribing is half of it. Are your notification settings set up to send you emails? Check your spam folder, just in case?

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
On 3/24/2023 at 9:14 AM, requinix said:

More like PhpSpreadsheet doesn't support something that's... well, it's weird, to put form elements into a spreadsheet. That's not what spreadsheets are for.

If you want better automation, have you considered VBA?

Subscribing is half of it. Are your notification settings set up to send you emails? Check your spam folder, just in case?

It is a custom spreadsheet, it has a checkbox to indicate a Male or a Female and I wish I could read those values using PHP since it is a webbased app. 

I only ticked this settings right now, hoping I will get notified later on.

Link to comment
Share on other sites

51 minutes ago, dee-u said:

It is a custom spreadsheet, it has a checkbox to indicate a Male or a Female and I wish I could read those values using PHP since it is a webbased app. 

I don't see how "my spreadsheet has a checkbox" and "PHP is web-based" are related...

The only other thing I can think of is highly specialized: if PHP is running on a Windows machine that has Office installed then you can probably make use of COM.
If that's the case then the first step towards using that would be writing VBA that does everything you need to do instead of PhpSpreadsheet.

Link to comment
Share on other sites

11 minutes ago, requinix said:

I don't see how "my spreadsheet has a checkbox" and "PHP is web-based" are related...

The only other thing I can think of is highly specialized: if PHP is running on a Windows machine that has Office installed then you can probably make use of COM.
If that's the case then the first step towards using that would be writing VBA that does everything you need to do instead of PhpSpreadsheet.

The web app needs to import the excel file and read its values. 

Link to comment
Share on other sites

As Requinix alluded to, this is not a limitation of PHP, it is a limitation of the PhpSpreadsheet library. Excel files have evolved into highly complex files well beyond what a "spreadsheet" is intended for. In this case the checkboxes are not "data" within the spreadsheet as it would normally exist. The checkboxes are objects that sit "on top of" those cells and are not the values within the cells. It would be possible to accomplish what you are after but it would require extensive knowledge of how those objects are defined within the file structure and even then could require elaborate logic within the code to figure out which checkboxes align with which row. The very simple solution is to change the structure of the spreadsheet so the "value" for that column is actually in the cells of that column. Instead of using checkbox elements on top of the cells, I would change those cells to use data validation so that the cell becomes a drop-down selection where the user can only choose True or False.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.