aspose.cell 设置excel里面的文字是超链接

目的:

1.通过方法designer.Workbook.Worksheets[0].Hyperlinks.Add("A1", 1, 1, url);给导出到excel里面的数据加上超链接

2.使用mvc进行测试

3.给A1,A2两个单元格加上超链接

4.给超链接加上超链接样式

5.添加超链接有2个方法

public int Add(string cellName, int rowNumber, int columnNumber, string address);
public int Add(int firstRow, int firstColumn, int rowNumber, int columnNumber, string address);

 

具体实现核心方法:

designer.Workbook.Worksheets[0].Cells[0, 0].PutValue("超链接1");

designer.Workbook.Worksheets[0].Cells[1, 0].PutValue("超链接2");

designer.Workbook.Worksheets[0].Hyperlinks.Add("A1", 1, 1, url);
designer.Workbook.Worksheets[0].Cells[0, 0].SetStyle(LinkStyle(designer.Workbook));

designer.Workbook.Worksheets[0].Hyperlinks.Add(1, 0, 1, 1, url);
designer.Workbook.Worksheets[0].Cells[1, 0].SetStyle(LinkStyle(designer.Workbook));

效果图

aspose.cell 设置excel里面的文字是超链接

 

入口方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public ActionResult chaolianjie()
      {
          string url = "http://www.baidu.com/";
          WorkbookDesigner designer = new WorkbookDesigner();
          string path = Server.MapPath("/Templete/DDD.xls");
          designer.Workbook.Open(path);
          //添加超链接
         <span style="background-color: rgb(255, 255, 0);"> designer.Workbook.Worksheets[0].Cells[0, 0].PutValue("超链接1");
          designer.Workbook.Worksheets[0].Cells[1, 0].PutValue("超链接2");
          designer.Workbook.Worksheets[0].Hyperlinks.Add("A1", 1, 1, url);
          designer.Workbook.Worksheets[0].Cells[0, 0].SetStyle(LinkStyle(designer.Workbook));
 
          designer.Workbook.Worksheets[0].Hyperlinks.Add(1, 0, 1, 1, url);
          designer.Workbook.Worksheets[0].Cells[1, 0].SetStyle(LinkStyle(designer.Workbook));</span>
          designer.Process();
 
          //将流文件写到客户端流的形式写到客户端,名称是_report.xls
          designer.Save("_report.xls", SaveType.OpenInExcel, FileFormatType.Excel2003, System.Web.HttpContext.Current.Response);
          Response.Flush();
          Response.Close();
          designer = null;
          // Response.End();
          return View("getexcel");
      }

aspose.cell 设置excel里面的文字是超链接

上一篇:iOS App用WKWebView加载h5, h5多页面手势返回,h5返回App


下一篇:http-自签证书