开发者

Hyperlink will not show Display proper text

开发者 https://www.devze.com 2023-03-11 18:59 出处:网络
I am trying to add a hyperlink to a cell to open a folder the code below makes the hyperlink in the proper cell and is when clicked redirects to the proper folder but it does not display the text prov

I am trying to add a hyperlink to a cell to open a folder the code below makes the hyperlink in the proper cell and is when clicked redirects to the proper folder but it does not display the text provided it instead displays the folder name e.g. (:C:\Documents and Settings\abulle\Desktop\Python-Stuff\Spec-Load\Formatted\) instead of 'Folder'

sheet.Hyperlinks.Add( Anc开发者_如何学JAVAhor = sheet.Cells(7,21), Address = "C:\\Python-Stuff\\Spec-Load\\Formatted\\" , TextToDisplay = "Folder")


I have a stopgap answer, a kludge. I don't have time at the moment to find a better answer. If this was part of my day job I'd spend the time to find out what's going on.

I've had the same issue (Excel shows the link address as the cell text instead of the TextToDisplay value supplied on Hyperlinks.Add())

My code works under unit test when invoked by running the Python 2.7 interpreter - the value of the 'TextToDisplay' argument is displayed in the cell. The 'production' code (built using py2exe) displays the hyperlink. I'll find out why some day (this is low background work.)

Hyperlinks.Add returns the Hyperlink object it just added. The workaround is to examine the TextToDisplay property of that object - if it's not what I want, I assign the correct value to it.

link = sheet.Hyperlinks.Add( Anchor = sheet.Cells(7,21),
                             Address = u"C:\\Python-Stuff\\Spec-Load\\Formatted\\" ,
                             TextToDisplay = u"Folder")
if link.TextToDisplay != u"Folder":
    link.TextToDisplay = u"Folder" # kludge


try this

 def addHyperlink(self, uri_1, summa_, sheetId, rowIndex, colIndex):
    requests = []
    requests.append({
        "updateCells": {
            "rows": [{
                "values": [{
                    'userEnteredValue': {'numberValue': floatG(summa_)},  #
                    'effectiveValue': {'numberValue': floatG(summa_)},
                    'formattedValue': "р." + summa_,
                    'userEnteredFormat': {
                        'numberFormat': {'type': 'NUMBER', 'pattern': '[$р.-419]#,##0.00'},
                        'backgroundColor': {'red': 1, 'green': 1, 'blue': 0.6}, 'borders': {
                            'top': {
                                'style': 'SOLID', 'width': 1, 'color': {}, 'colorStyle': {'rgbColor': {}}},
                            'bottom': {
                                'style': 'SOLID', 'width': 1, 'color': {}, 'colorStyle': {'rgbColor': {}}},
                            'left': {
                                'style': 'SOLID', 'width': 1, 'color': {}, 'colorStyle': {'rgbColor': {}}},
                            'right': {
                                'style': 'SOLID', 'width': 1, 'color': {}, 'colorStyle': {'rgbColor': {}}}},
                        'horizontalAlignment': 'RIGHT', 'verticalAlignment': 'BOTTOM',
                        'textFormat': {
                            'foregroundColor': {'red': 0.06666667, 'green': 0.33333334, 'blue': 0.8},
                            'fontFamily': 'Arial', 'underline': True,
                            'foregroundColorStyle': {
                                'rgbColor': {'red': 0.06666667, 'green': 0.33333334, 'blue': 0.8}},
                            'link': {'uri': uri_1}
                        },
                        'hyperlinkDisplayType': 'LINKED',
                        'backgroundColorStyle': {'rgbColor': {'red': 1, 'green': 1, 'blue': 0.6}}
                    }
                    , 'hyperlink': uri_1, 'note': 'макс',
                }
                ]
            }], "fields": "userEnteredFormat(numberFormat,backgroundColor,horizontalAlignment,verticalAlignment,textFormat)", "start": {
                "sheetId": sheetId, "rowIndex": rowIndex, "columnIndex": colIndex}}})
    body = {
        "requests": requests}
    request = self.service.spreadsheets().batchUpdate(spreadsheetId=self.spreadsheetId, body=body)
    return request.execute()
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号