epplus输出成thml
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();
}
} } }
epplus输出成thml的更多相关文章
- 将包含经纬度点位信息的Excel表格数据导入到ArcMap中并输出成shapefile
将包含经纬信息的Excel表格数据,导入到ArcMap中并输出成shapefile,再进行后面的操作.使用这种方法可以将每一个包含经纬信息的数据在ArcMap中点出来. 一.准备数据 新建Excel表 ...
- 微软BI 之SSIS 系列 - 两种将 SQL Server 数据库数据输出成 XML 文件的方法
开篇介绍 在 SSIS 中并没有直接提供从数据源到 XML 的转换输出,Destination 的输出对象有 Excel File, Flat File, Database 等,但是并没有直接提供 X ...
- js格式化文件大小, 输出成带单位的字符串工具
/** * 格式化文件大小, 输出成带单位的字符串 * @method formatSize * @grammar formatSize( size ) => String * @grammar ...
- Python怎么控制将一个整数输出成指定长的十六进制数?
使用format方法,在格式控制中进行控制,具体控制参数为: {:#016X} 其中: 大括号表示该处从后面的format的参数中取值 冒号表示格式控制开始 0表示长度不足16位补0 16表示长度 X ...
- CAD的输出成高清jpg图片
打印名称选择JPG或者PNG 然后图纸尺寸选择大的 尺寸不够大就自己设置下 创建新图纸——设置下长宽——然后保存下名字,然后图纸尺寸选择你设置过的这个输出就好了 然后窗口下就好了
- 把aspx页面输出成xml的方法注意事项
先贴代码 Response.Charset = "gb2312"; Response.ContentType = "text/xml"; Response.Co ...
- 把sql输出成。sql文件
作者原创,转载注明出处: 代码: package importfile; import java.io.*; import java.io.PrintWriter; import java.sql.C ...
- c# gdi+输出成不同mime类型的图片
/// <summary> /// 通过图片的mime类型得到相应的编码器 /// </summary> /// <param name="mimeType&q ...
- FOR XML PATH 可以将查询结果根据行输出成XML格式
SELECT CAST(OrderID AS varchar)+',' as OrderNo FROM Product CAST函数用于将某种数据类型的表达式显式转换为另一种数据类型 SELECT C ...
随机推荐
- AE属性表操作
转自chanyinhelv原文AE属性表操作 实现的操作包括:1.打开属性表:2.编辑属性表:3.增加属性列:4.数据排序:5.字段计算…… 嗯,实现的功能目前就这些吧,后续还会继续跟进,还望大家多多 ...
- [Angular] Pipes as providers
In this example, we are going to see how to use Pipe as providers inject into component. We have the ...
- [Angular] Some performance tips
The talk from here. 1. The lifecycle in Angular component: constructor vs ngOnInit: Constructor: onl ...
- JUnit中@Test的运行顺序
原文链接: Test execution order 原文日期: 2012年12月06日 翻译日期: 2014年10月16日 翻译人员: 百里马 依照设计,Junit不指定test方法的运行顺序. 到 ...
- 在CentOS系统上将deb包转换为rpm包
转载自 http://www.heminjie.com/system/linux/1487.html deb文件格式本是ubuntu/debian系统下的安装文件,那么我想要在redhat/cento ...
- Qt 元对象系统(Meta-Object System)(不管是否使用信号槽,都推荐使用)
Qt 元对象系统(Meta-Object System) Qt的元对象系统基于如下三件事情: 类:QObject,为所有需要利用原对象系统的对象提供了一个基类. 宏:Q_OBJECT,通常可以声明在类 ...
- 深度剖析:最新云端开发工具如何实现敏捷+DevOps开发落地
相信很多软件开发人员们对今年国内新兴的云端开发工具——华为软件开发云都有耳闻,有些人可能还免费体验过,由于它5人以下的团队是免费使用的,很庆幸本人的这个项目正好5个人,就注册使用了.下面就自己的使用心 ...
- 手推机器学习公式(一) —— BP 反向传播算法
方便起见,本文仅以三层的神经网络举例. f(⋅):表示激励函数 xi:表示输入层: yj:表示中间的隐层: yj=f(netj) netj=∑i=0nvijxi ok:表示输出层,dk 则表示期望输出 ...
- SQL Server 存储过程之嵌套游标
下面是一个订单取消的含2个游标的存储过程 set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER PROCEDURE [dbo].[CancelOrde ...
- Hibernate——(1)Hibernate入门
一.Hibernate简介 1.Hibernate是一款ORM框架,Object Relation Mapping 对象关系映射. 2.可以将DB映射成Object,这样程序只要对Object对象进行 ...