PydPiper / pylightxl

A light weight, zero dependency, minimal functionality excel read/writer python library
https://pylightxl.readthedocs.io
MIT License
290 stars 47 forks source link

& replaced by & when writing a URL with parameters in it #86

Open dmcnulla opened 1 year ago

dmcnulla commented 1 year ago

Pylightxl Version: 1.60 Python Version: 3.10.0

Summary of Bug/Feature: I added a URL to my spreadsheet (simple str object) that contained an ampersand to separate URL parameters. The URL was written with the "&" replaced by "&" which makes the URL unusable when it is read later.

Example: https://myconfluenceserver/pages/viewpage.action?spaceKey=QTA&title=Some+Title is written as https://myconfluenceserver/pages/viewpage.action?spaceKey=QTA&title=Some+Title

Traceback: N/A

Suggestion for fix: Either do not modify the string, or allow for some alternative way to write a URL so it gets written unchanged from the intention.

String seems to get modified in pylightxl.py line 1242/1243:

                    db._sharedStrings.append(val.replace('&', '&'))
                    val = db._sharedStrings.index(val.replace('&', '&'))

I am open to workarounds, but I prefer to not "fix the URL when reading later" because it feels really hacky. Maybe there is another way to encode the "&" so it isn't replaced? Maybe it has to be there to support the xml writing (not my area of expertise).

In the meantime, I will see if I can replace the url with confluence's shortened url.

My code to create the sheet:

    def create_sheet(self, sheet_name: str, data: List[any]):
        """
        Creates the xlsx sheet.
        :param sheet_name: The name of the xlsx sheet.
        :param data: Data to add into current sheet.
        """
        self._xl_db.add_ws(ws=sheet_name)
        for row_id, row in enumerate(data, start=1):
            for col_id, col in enumerate(row, start=1):
                self._xl_db.ws(ws=sheet_name).update_index(row=row_id, col=col_id, val=col)

My code to save the file:

    def write_temp_file(self):  # pragma: no cover
        """Create a temporary file (spreadsheet contents)."""
        filename = f'{self.site_id}.xlsx'
        pylightxl.writexl(db=self._xl_db, fn=filename)
        logging.info(f'APEX spreadsheet successfully saved as {filename}')
        return filename
dmcnulla commented 1 year ago

I changed my url format to the following which is an acceptable workaround for me: https://myconfluenceserver/display/QTA/Some+Title