using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OfficeOpenXml;
using System.IO;
using EPPlus.Html;
namespace testepplus
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string zpath = Server.MapPath("/") + "test1.xlsx";
FileInfo zfile = new FileInfo(zpath); using (ExcelPackage excel = new ExcelPackage(zfile,"123"))
{
//excel.SaveAs(new FileInfo(Server.MapPath("/") + "test1.xlsx"), "123");
Response.Write(EPPlus.Html.EPPlusExtensions.ToHtml(excel.Workbook.Worksheets[3])); } }
}
}

fx要4.5+ ,需要huget package  epplus ,epplus.html   

可以从https://github.com/fitogram/EPPlus.Html 下载源码更改fx为4.0

epplus.html 0.20版本不支持excel里的图片

修改epplus.html添加支持图片的不成熟的源码

using EPPlus.Html.Converters;
using EPPlus.Html.Html;
using OfficeOpenXml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Drawing;
namespace EPPlus.Html
{
public static class EPPlusExtensions
{
public static string ToHtml(this ExcelWorksheet sheet)
{
int lastRow = sheet.Dimension.Rows;
int lastCol = sheet.Dimension.Columns; HtmlElement htmlTable = new HtmlElement("table");
htmlTable.Attributes["cellspacing"] = 0;
htmlTable.Styles["white-space"] = "nowrap"; //render rows
for (int row = 1; row <= lastRow; row++)
{
ExcelRow excelRow = sheet.Row(row); var test = excelRow.Style;
HtmlElement htmlRow = htmlTable.AddChild("tr");
htmlRow.Styles.Update(excelRow.ToCss()); for (int col = 1; col <= lastCol; col++)
{
ExcelRange excelCell = sheet.Cells[row, col];
HtmlElement htmlCell = htmlRow.AddChild("td"); string cc = getPictureCode(row, col, sheet);
if (cc == "")
{
htmlCell.Content = excelCell.Text;
} else
{
htmlCell.Content = cc;
}
htmlCell.Styles.Update(excelCell.ToCss());
}
} return htmlTable.ToString();
} public static string getPictureCode(int row ,int col , ExcelWorksheet sheet)
{
foreach (OfficeOpenXml.Drawing.ExcelDrawing excelDrawing in sheet.Drawings)
{
OfficeOpenXml.Drawing.ExcelPicture excelPicture = excelDrawing as OfficeOpenXml.Drawing.ExcelPicture;
if (excelPicture.From.Column+1==col && excelPicture.From.Row+1 == row){
return "<img src = \"data:image/jpeg;base64," + ImgToBase64String(excelPicture.Image) + "\"/>";
} }
return "";
} public static CssInlineStyles ToCSS(this ExcelStyles styles)
{
throw new NotImplementedException();
} public static string ImgToBase64String(Image image)
{
MemoryStream ms = new MemoryStream();
try
{ image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] arr = new byte[ms.Length];
ms.Position = 0;
ms.Read(arr, 0, (int)ms.Length);
return Convert.ToBase64String(arr);
}
catch (Exception ex)
{
return "";
}
finally
{
ms.Close();
}
} } }

  

最新文章

  1. 【Oracle】表空间容量修改
  2. {A} + {B} 分类: HDU 2015-07-11 18:06 6人阅读 评论(0) 收藏
  3. php大力力 [016节] 兄弟连高洛峰php教程(2014年 14章数据库章节列表)
  4. Android学习笔记之AndroidManifest.xml文件解析
  5. [COCOS2DX]官网helloworld在VS2012中的部署
  6. MAC地址查询 Linux/Unix操作系统mac地址怎么查
  7. 设计模式入门之桥接模式Bridge
  8. CSU 1515 Sequence
  9. HBuilder的webview操作
  10. selenium+python开发环境的搭建
  11. FWT模板
  12. 浅析布隆过滤器及实现demo
  13. 1344:【例4-4】最小花费 dijkstra
  14. python冒泡排序法
  15. C语言基础三(敲打键盘、寻找资料,循环语句)
  16. jq ‘’操作‘’伪元素
  17. Halcon常用算子01
  18. Django 时间与时区设置问题
  19. soj1010. Zipper
  20. 6 TensorFlow实现cnn识别手写数字

热门文章

  1. 【Windows Defender Antivirus Service 永久禁用 】
  2. uva 1519 - Dictionary Size(字典树)
  3. gen_server的enter_loop分析
  4. BZOJ1415 聪聪与可可 - 期望dp
  5. PCI的imagework已由freeview软件代替
  6. 通过一次SpringBoot打成war包部署到tomcat启动总结一般jar包冲突的解决方法
  7. rac下一个/tmp/bootstrap权限问题
  8. Sleep(0)的妙用
  9. java写文件时往末尾追加文件(而不是覆盖原文件),的两种方法总结
  10. POJ 3904(容斥原理)