none
the cell did not display any text

    Question

  •        I am trying to add hyperlink and display text to a cell. I found that the hyperlink is written to the cell but there is no display text for the link. I do try to add the text but it seems my code is having some problem. The follows is my code. Please help.

    {
    string[] words = data.Split('!');
    
    string cellReference = string.Format("{0}{1}", columnText, rowIndex);
    string uniqueID = "hyperlink" + linkIndex.ToString();
    Hyperlink hyperlink1 = new Hyperlink() { Reference = cellReference, Id = uniqueID };
    hyperlinks1.Append(hyperlink1);
    wsPart.Worksheet.Save();
    wsPart.AddHyperlinkRelationship(new System.Uri(attachmentDownloadURL + "?id=" + words[0].ToString(), System.UriKind.Absolute), true, uniqueID);
    
    // add hyperlink text to shared string table
    shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new DocumentFormat.OpenXml.Spreadsheet.Text(words[1])));
    shareStringPart.SharedStringTable.Save();
    
    cell.CellReference = cellReference;
    
    cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
    cell.CellValue = new CellValue(linkIndex.ToString());
    cell.StyleIndex = styleHyperlink;
    linkIndex++;
    }


    hon123456

    mardi 8 mai 2018 13:45

Toutes les réponses

  • Hello hon123456,

    I did not see where you save the cell to the worksheet part. Have you ever done it?

    If not, you need insert the cell to the worksheet part first.

    If you have done, I would suggest you use Open XML SDK Tools to check if the string of words[1] is indeed inserted in to the SharedStringTablePart first. And then, I would suggest you use the words[1] to loop through the SharedStringTablePart to return an index of the words[1] instead of hardcoding to assign a linkindex for it.

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    mercredi 9 mai 2018 05:00
    Modérateur
  • Thanks Terry. You are correct. I have not append the cell to the row.

    hon123456

    mercredi 9 mai 2018 09:21
  • Hello hon123456,

    I'm glad to hear that you have solved the issue. I would suggest you mark any helpful reply or your solution as answer to close this thread. If you have any other issue, please fell free to post threads to let us know.

    Thanks for understanding.

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    mercredi 9 mai 2018 09:23
    Modérateur