打开DevExpress的ASPxSpreadsheet中的HTML链接。

huangapple go评论83阅读模式
英文:

Open HTML link from devexpress's ASPxSpreadsheet

问题

正如标题所示,我想要打开一个HTML链接,但我不确定我目前的做法是否正确。我正在使用超链接,但似乎对我不起作用。以下是我正在使用的代码片段:

CellRange nameFileCellRange = secondWorksheet.Cells["C7"];
nameFileCellRange.Value = "Drawing: " + fileName;

Hyperlink nameFileHyperlink = secondWorksheet.Hyperlinks.Add(nameFileCellRange, "javascript:openFile(" + filename + ")", true, filename);
nameFileHyperlink.TooltipText = "open";

这是JavaScript函数:

function openFile(fileName) {
    console.log("hi");
    var _url = "./TraceabilityNP.aspx?id=" + encodeURIComponent(fileName);
    var _name = "VIEWFILE"
    var w = 600;
    var h = 400;

    var x = window.open(_url, _name, "width=" + w + ", height=" + h);
    x.focus();
}

请问可能出错的原因是什么?或者还有其他方法可以尝试吗?

英文:

As indicated in the title, I would like to open a HTML link, but I'm uncertain if what I'm currently doing is correct. I'm using a hyperlink, but it doesn't seem to be working for me. Here's the code snippet I'm using:

CellRange nameFileCellRange = secondWorksheet.Cells["C7"];
nameFileCellRange.Value = "Drawing: " + fileName;

Hyperlink nameFileHyperlink = secondWorksheet.Hyperlinks.Add(nameFileCellRange, "javascript:openFile(" + filename + ")", true, filename);
nameFileHyperlink.TooltipText = "open";

And here's the JavaScript function:

function openFile(fileName) {
    console.log("hi");
    var _url = "./TraceabilityNP.aspx?id=" + encodeURIComponent(fileName);
    var _name = "VIEWFILE";
    var w = 600;
    var h = 400;

    var x = window.open(_url, _name, "width=" + w + ", height=" + h);
    x.focus();
}

Could you please let me know what might be going wrong? Alternatively, are there any other approaches I could try?

答案1

得分: 2

请注意以下来自官方DevExpress网站的信息:

ASPxSpreadsheet不允许使用URL打开文件

支持的方法在这里列出(请注意没有URL):

ASPxSpreadsheet.Open方法

更新1(唯一单元格):
由于您可以使用Devex客户端事件(纯JavaScript),您需要做两件事:

1. 在服务器端(请注意虚拟URI)

        Cell cell = worksheet1.Cells["B4"]; //这是为一个单元格,您可以使用CellRange用于N个单元格。
        var fileUrl = "https://github.com/DevExpress-Examples/winforms-spreadsheetcontrol-api-part1/blob/23.1.2%2B/Readme.md";
        worksheet1.Hyperlinks.Add(cell, fileUrl, true, "DevExpress Spreadsheet Repo");

2. 在客户端

使用工作表的HyperlinkClick客户端事件,并定义如下(请注意,我在#1中使用了虚拟URI):

  <ClientSideEvents 
            HyperlinkClick="function(s, e) {             
            var _url=e.targetUri;
            var _name = 'VIEWFILE'
            var w = 600;
            var h = 400;                                    
            var x= window.open(_url,_name,'width=' + w + ',height=' + h); 
            x.focus();            
            e.handled = true;           
            }"
        />

更新2(单元格范围):

1. 在服务器端(请注意虚拟URI)

CellRange nameFileCellRange = secondWorksheet.Range["C7"]; //请注意,您可以指定一系列单元格,例如["C7:C10"]
        string url= "https://github.com/DevExpress-Examples/winforms-spreadsheetcontrol-api-part1/blob/23.1.2%2B/Readme.md";
        nameFileCellRange.Value = "Drawing: " + url;
        Hyperlink nameFileHyperlink = secondWorksheet.Hyperlinks.Add(nameFileCellRange, url, true, nameFileCellRange.Value.ToString());
        nameFileHyperlink.TooltipText = "open";

2. 在客户端(实际上与第一个更新的单元格相同的代码)

使用工作表的HyperlinkClick客户端事件,并定义如下(请注意,我在#1中使用了虚拟URI):

<ClientSideEvents 
    HyperlinkClick="function(s, e) {                         
    var _url = e.targetUri;            
    var _name = 'VIEWFILE';
    var w = 600;
    var h = 400;                                    
    var x= window.open(_url,_name,'width=' + w + ',height=' + h); 
    x.focus();            
    e.handled = true;           
    }"
/>
英文:

Please take into account the following information from official Devexpress site:

ASPxSpreadsheet does not allow opening files using URL

The supported methods are listed here (notice NO Url):

ASPxSpreadsheet.Open Method

UPDATE 1 (Unique Cell):
Since you can use devex clientsideevents (pure javascript) what you need to do are two things:

1. On the server side (notice the dummy URI)

        Cell cell = worksheet1.Cells["B4"]; //This is for one cell you can use CellRange for N cells.
        var fileUrl = "https://github.com/DevExpress-Examples/winforms-spreadsheetcontrol-api-part1/blob/23.1.2%2B/Readme.md";
        worksheet1.Hyperlinks.Add(cell, fileUrl, true, "DevExpress Spreadsheet Repo");

2. On the client

Use the HyperlinkClick client side event for the worksheet and define it as follows(notice im using a dummy URI previously loaded on #1):

  <ClientSideEvents 
            HyperlinkClick="function(s, e) {             
            var _url=e.targetUri;
            var _name = 'VIEWFILE';
            var w = 600;
            var h = 400;                                    
            var x= window.open(_url,_name,'width=' + w + ',height=' + h); 
            x.focus();            
            e.handled = true;           
            }"
        />

UPDATE 2 (Cell Range):

1. On the server side (notice the dummy URI)

CellRange nameFileCellRange = secondWorksheet.Range["C7"]; //Notice you can specify a range of cells ir ["C7:C10"]
        string url= "https://github.com/DevExpress-Examples/winforms-spreadsheetcontrol-api-part1/blob/23.1.2%2B/Readme.md";
        nameFileCellRange.Value = "Drawing: " + url;
        Hyperlink nameFileHyperlink = secondWorksheet.Hyperlinks.Add(nameFileCellRange, url, true, nameFileCellRange.Value.ToString());
        nameFileHyperlink.TooltipText = "open";

2. On the client (actually is the same code as first update with single cell)

Use the HyperlinkClick client side event for the worksheet and define it as follows(notice im using a dummy URI previously loaded on #1):

<ClientSideEvents 
    HyperlinkClick="function(s, e) {                         
    var _url = e.targetUri;            
    var _name = 'VIEWFILE';
    var w = 600;
    var h = 400;                                    
    var x= window.open(_url,_name,'width=' + w + ',height=' + h); 
    x.focus();            
    e.handled = true;           
    }"
/>

huangapple
  • 本文由 发表于 2023年6月16日 05:31:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76485647.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定