如题,我想给导出的excel表的指定列添加超链接,该怎么做呢?最好说说在后台怎么写导出excel表的样式来添加超链接,而不是建excel模板来实现。。谢谢了,

解决方案 »

  1.   

                    HSSFHyperlink hl1 = new HSSFHyperlink(HyperlinkType.URL);
                    hl1.Address = ""; // 超链接
                    hl1.Label = ""; // 链接名称
                    sheet.GetRow(3).GetCell(0).Hyperlink = hl1;
      

  2.   

    单元格本来就有Hyperlink的属性,你创建一个超链接对象,赋给它就行了。
      

  3.   


    伤不起啊,试试,。谢谢LisLiefor,昨天你也来回哒问题了,昨天我鳖了半天还是自己把问题解决了,谢谢你了哈,。第一次做Excel导出   呵呵
      

  4.   


    找不到你给出的引用,。  我这里有 Excel.Hyperlink的,.我就这样子写的:
    Excel.Hyperlink hl = new Excel.Hyperlink();  不知道怎么给参数了,我这里没有HyperlinkType 
      

  5.   

    直接使用html代码加链接,导出的excel的数据本身就是html格式的,导出后你可以查看源代码,就是一段table的代码~~
      

  6.   

    可能我到处excel的方法不一样,我贴我的导出方法出来。看这个帖子:
    求解asp.net mvc 中上传excel 如何导入到数据库中!!!
      

  7.   


    public MemoryStream ExportQualifiedExaminees(string modelPath, string serviceName, IList<QualifiedExamineeEn> lst, string imgPath)
            {
                MemoryStream imageStream = new MemoryStream();
                HSSFWorkbook workbook = new HSSFWorkbook(File.OpenRead(modelPath));
                Image.FromFile(imgPath).Save(imageStream, System.Drawing.Imaging.ImageFormat.Png);
                byte[] bytes = new byte[imageStream.Length];
                bytes = imageStream.GetBuffer();            imageStream = null;
                //int picInt = ;
                HSSFClientAnchor ac = new HSSFClientAnchor(0, 0, 0, 0, 0, 0, 1, 1);
                Row r = workbook.GetSheet("合格考生名单").GetRow(4);
                var style = r.GetCell(0).CellStyle;
                var type = r.GetCell(0).CellType;            IEnumerable<IGrouping<string, QualifiedExamineeEn>> list = lst.GroupBy(m => m.ExamLocationName);            for (int i = 0; i < list.Count(); i++)
                {
                    List<QualifiedExamineeEn> ls = list.ElementAt(i).ToList<QualifiedExamineeEn>();                Sheet sheet = workbook.CloneSheet(0);
                    workbook.SetSheetName(i + 1, ls[0].ExamLocationName);
                    var patriarch = sheet.CreateDrawingPatriarch();                patriarch.CreatePicture(ac, workbook.AddPicture(bytes, PictureType.PNG)).Resize();
                    sheet.GetRow(2).GetCell(0).SetCellValue("考试服务名称:" + serviceName);
                    sheet.GetRow(3).GetCell(0).SetCellValue("考场地址:" + ls[0].LocationAddress);                int countFlag = 1;
                    foreach (var m in ls)
                    {
                        var newRow = sheet.CreateRow(sheet.LastRowNum + 1);
                        newRow.HeightInPoints = 18;
                        if (m.IDNumber == null || m.IDNumber.Length == 0)
                        {
                            CreateCell(newRow, 0, style, type, countFlag.ToString());
                            CreateCell(newRow, 1, style, type, m.AdmissionFormId.ToString());
                            CreateCell(newRow, 2, style, type, "");
                            CreateCell(newRow, 3, style, type, "");
                            CreateCell(newRow, 4, style, type, "");
                            CreateCell(newRow, 5, style, type, "");
                            CreateCell(newRow, 6, style, type, "");
                            CreateCell(newRow, 7, style, type, "");
                            CreateCell(newRow, 8, style, type, "");
                        }
                        else
                        {
                            CreateCell(newRow, 0, style, type, countFlag.ToString());
                            CreateCell(newRow, 1, style, type, m.AdmissionFormId.ToString());
                            CreateCell(newRow, 2, style, type, m.FirstName + " " + m.LastName);
                            CreateCell(newRow, 3, style, type, m.Gender ? "男" : "女");
                            CreateCell(newRow, 4, style, type, m.Birthday);
                            CreateCell(newRow, 5, style, type, m.Department);
                            CreateCell(newRow, 6, style, type, m.IDNumber);
                            CreateCell(newRow, 7, style, type, "");
                            CreateCell(newRow, 8, style, type, "");
                        }
                        countFlag++;
                    }
                }            workbook.RemoveSheetAt(0);
                MemoryStream ms = new MemoryStream();
                workbook.Write(ms);
                workbook = null;
                r = null;            return ms;
            }
      

  8.   

    请问如何取消导出excel的超链接?????????
    ???????