asp.net导出excel 加超链接 如题,我想给导出的excel表的指定列添加超链接,该怎么做呢?最好说说在后台怎么写导出excel表的样式来添加超链接,而不是建excel模板来实现。。谢谢了, 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 HSSFHyperlink hl1 = new HSSFHyperlink(HyperlinkType.URL); hl1.Address = ""; // 超链接 hl1.Label = ""; // 链接名称 sheet.GetRow(3).GetCell(0).Hyperlink = hl1; 单元格本来就有Hyperlink的属性,你创建一个超链接对象,赋给它就行了。 伤不起啊,试试,。谢谢LisLiefor,昨天你也来回哒问题了,昨天我鳖了半天还是自己把问题解决了,谢谢你了哈,。第一次做Excel导出 呵呵 找不到你给出的引用,。 我这里有 Excel.Hyperlink的,.我就这样子写的:Excel.Hyperlink hl = new Excel.Hyperlink(); 不知道怎么给参数了,我这里没有HyperlinkType 直接使用html代码加链接,导出的excel的数据本身就是html格式的,导出后你可以查看源代码,就是一段table的代码~~ 可能我到处excel的方法不一样,我贴我的导出方法出来。看这个帖子:求解asp.net mvc 中上传excel 如何导入到数据库中!!! 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; } 请问如何取消导出excel的超链接???????????????? 登录数据库失败 |zyciis| 一个简单的题 short s= 1 ; s=s+1 出错 一个引用公共类的问题 菜鸟急等 我想编asp.net程序,不知道这个Cassini是否可以代替IIS 各位高手,关于treeview控件的使用!帮帮忙! DropDownList数据绑定显示问题 超级奇怪的问题,您来试试! 一个jquery ajax框架+json的问题 在线等。。。 如何把一个xml文件的内容绑定到一个RadioButtonList控件中呢? js 获取参数的疑惑 if()else {这里可以再跳回到if判断吗?大家有遇到吗}
hl1.Address = ""; // 超链接
hl1.Label = ""; // 链接名称
sheet.GetRow(3).GetCell(0).Hyperlink = hl1;
伤不起啊,试试,。谢谢LisLiefor,昨天你也来回哒问题了,昨天我鳖了半天还是自己把问题解决了,谢谢你了哈,。第一次做Excel导出 呵呵
找不到你给出的引用,。 我这里有 Excel.Hyperlink的,.我就这样子写的:
Excel.Hyperlink hl = new Excel.Hyperlink(); 不知道怎么给参数了,我这里没有HyperlinkType
求解asp.net mvc 中上传excel 如何导入到数据库中!!!
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;
}
???????