qa:c#文本字符串插入双引号:@用法和反斜杠用法

Excel中添加超链接,可以用hyperlink公式,即=hyperlink(src,display);

在stackoverflow中的示例中:http://stackoverflow.com/questions/2905633/add-hyperlink-to-cell-in-excel-2007-using-open-xml-sdk-2-0

CellFormula cellFormula1 = new CellFormula() { Space = SpaceProcessingModeValues.Preserve };
cellFormula1.Text = @"HYPERLINK(""http://www.theclash.com"", ""Radio Clash"")";

上面方式中,@表示其后的字符串可以当作普通字符串来处理,不需考虑反斜杠可能引发的转义情况。对于普通字符串中包括的双引号,用2个双引号来表示。

但将链接替换为变量时,这种方式则不可取,关键是@用法的限制。

可以直接用字符串拼接的方式,对于双引号,用反斜杠进行转义字符。

url="http://www.theclash.com";

txt=String.Concat("HYPERLINK(\"",url,"\", \"Radio Clash\")");

posted on 2016-05-03 15:33  青天一色  阅读(4951)  评论(0编辑  收藏  举报

导航