dee-u Posted March 20, 2023 Share Posted March 20, 2023 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. Quote Link to comment https://forums.phpfreaks.com/topic/316022-read-checkbox-value-embedded-on-excel-file/ Share on other sites More sharing options...
requinix Posted March 20, 2023 Share Posted March 20, 2023 According to this, PhpSpreadsheet only detects them for Excel 2007 files and even then you can't get their properties. Quote Link to comment https://forums.phpfreaks.com/topic/316022-read-checkbox-value-embedded-on-excel-file/#findComment-1606639 Share on other sites More sharing options...
dee-u Posted March 24, 2023 Author Share Posted March 24, 2023 (edited) 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 March 24, 2023 by dee-u Quote Link to comment https://forums.phpfreaks.com/topic/316022-read-checkbox-value-embedded-on-excel-file/#findComment-1606775 Share on other sites More sharing options...
requinix Posted March 24, 2023 Share Posted March 24, 2023 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? 1 Quote Link to comment https://forums.phpfreaks.com/topic/316022-read-checkbox-value-embedded-on-excel-file/#findComment-1606777 Share on other sites More sharing options...
dee-u Posted April 3, 2023 Author Share Posted April 3, 2023 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. Quote Link to comment https://forums.phpfreaks.com/topic/316022-read-checkbox-value-embedded-on-excel-file/#findComment-1607027 Share on other sites More sharing options...
requinix Posted April 3, 2023 Share Posted April 3, 2023 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. Quote Link to comment https://forums.phpfreaks.com/topic/316022-read-checkbox-value-embedded-on-excel-file/#findComment-1607028 Share on other sites More sharing options...
dee-u Posted April 3, 2023 Author Share Posted April 3, 2023 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. Quote Link to comment https://forums.phpfreaks.com/topic/316022-read-checkbox-value-embedded-on-excel-file/#findComment-1607029 Share on other sites More sharing options...
Psycho Posted April 5, 2023 Share Posted April 5, 2023 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. Quote Link to comment https://forums.phpfreaks.com/topic/316022-read-checkbox-value-embedded-on-excel-file/#findComment-1607059 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.