dalefarnsworth-dmr / codeplug

GNU Lesser General Public License v3.0
3 stars 2 forks source link

Empty .xlsx fields cause problems #3

Closed cxbrooks closed 2 years ago

cxbrooks commented 3 years ago

Under macOS, it seems that when I export a .xslx file, and then reimport it, I get problems with blank fields being introduced.

To replicate this, under macOS with editcp 1.0.23 and a TYT MD-UV390:

  1. Read the codeplug from the radio
  2. File -> Export -> Export to Spreadsheet
  3. Exit editcp
  4. Restart editcp
  5. File -> Import -> Import Spreadsheet file

The following message appears:

55 records with invalid field values were found in the codeplug.

Select "Menu->Edit->Show Invalid Fields" to view them.

The invalid fields are:

The following field values are invalid:

Zones[GMRS].A Channels[=INVALID=]: bad Channels name: ''
Zones[GMRS].A Channels[=INVALID=]: bad Channels name: ''
Zones[GMRS].A Channels[=INVALID=]: bad Channels name: ''
Zones[GMRS].A Channels[=INVALID=]: bad Channels name: ''
Zones[GMRS].A Channels[=INVALID=]: bad Channels name: ''

etc.

Here's the file that was exported: codeplug3.xlsx

BTW - I opened the .xslx file that was created and oddly the rows cannot be displayed? I tried unhiding them by selecting the first row displayed (row 58 in the Zones tab) and then right clicking and selecting unhide, but the other rows were not displayed. I guess that would be a separate issue...

I was able to export the Zones tab as a csv file and I can see that the first row has empty fields:

GMRS,GMRS1,GMRS2,GMRS3,GMRS4,GMRS5,GMRS6,GMRS15,GMRS16,GMRS17,GMRS18,GMRS19,GMRS20,GMRS21,GMRS22,FRS1,FRS2,FRS3,FRS4,FRS5,FRS6,FRS7,GMRS7,FRS8LP,FRS9LP,FRS10LP,FRS11LP,FRS12LP,FRS13LP,FRS14LP,MURS1,MURS2,MURS3,MURS4BLUE,MURS5GREEN,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

My solution is to modify go/src/github.com/dalefarnsworth-dmr/codeplug/codeplug.go:

index 5c1f147..e1b9ec1 100644
--- a/codeplug.go
+++ b/codeplug.go
@@ -2176,12 +2176,15 @@ func (cp *Codeplug) parseXLSXFile(iRdr io.Reader) []*parsedRecord {
            colIndex := 0
            row.ForEachCell(func(cell *xlsx.Cell) error {
                str := cell.String()
-               fType := fTypeNames[colIndex]
-               parField := parsedField{
-                   name:  fType,
-                   value: str,
-               }
-               parFields = append(parFields, &parField)
+                                // Skip empty fields
+                                if len(str) > 0 {
+                   fType := fTypeNames[colIndex]
+                   parField := parsedField{
+                       name:  fType,
+                       value: str,
+                   }
+                       parFields = append(parFields, &parField)
+                                }
                colIndex++
                return nil
            })
DaleFarnsworth commented 3 years ago

Thank you. I don't have a mac, but at first glance this fix looks safe. I'll test out your fix on x86 within a couple of days.

cxbrooks commented 3 years ago

I'm not way up on the interface to Excel or Excel itself, but ideally there would be a way to check between a cell that had no type (that had never been set) vs. a cell that had a type of string and the string was empty. Checking for an unset type might be safer than checking for a string of length 0.

Tomorrow, I'll see if I can run down the oddity of not having all the rows visible. It was working until I updated my go libraries. I was at the git head in editcp, but the libraries might have been old. I'm not way up on how go works either so who knows.

BTW - many thanks for editcp, I'm happy to be able to program the radio via a native Mac app instead of running software in a Windows VM.

DaleFarnsworth commented 2 years ago

Well, better late than never, I guess. I applied the above change in commit d999b862d18ad91a5f753bab4f0ab4ee0a4d6b49. Thank you again.

DaleFarnsworth commented 2 years ago

It's available in editcp v1.0.27.