zoukankan
html css js c++ java
导出Excel(利用xml标记)
using
System;
using
System.Data;
using
System.Web;
using
System.Text;
using
System.IO;
/**/
///
<summary>
///
生成Excel数据并返回文件名称
///
strData为要显示的内容--Html编码格式
///
</summary>
///
<param name="strData"></param>
///
<returns></returns>
public
static
string
strCreateExcelAndReturnFileName(
string
strData)
{
string
strFileName
=
"
myData.xls
"
;
//
====================================================
StringBuilder sb
=
new
StringBuilder();
sb.Append(
"
<html xmlns:o=\
"
urn:schemas
-
microsoft
-
com:office:office\
""
);
sb.Append(
"
xmlns:x=\
"
urn:schemas
-
microsoft
-
com:office:excel\
""
);
sb.Append(
"
xmlns=\
"
http:
//
www.w3.org/TR/REC-html40\">");
sb.Append(
"
<head>
"
);
sb.Append(
"
<meta http-equiv=Content-Type content=\
"
text
/
html; charset
=
gb2312\
"
>
"
);
sb.Append(
"
<meta name=ProgId content=Excel.Sheet>
"
);
sb.Append(
"
<meta name=Generator content=\
"
Microsoft Excel
10
\
"
>
"
);
sb.Append(
"
<!--[if gte mso 9]><xml>
"
);
sb.Append(
"
<x:ExcelWorkbook>
"
);
sb.Append(
"
<x:ExcelWorksheets>
"
);
sb.Append(
"
<x:ExcelWorksheet>
"
);
sb.Append(
"
<x:Name>电信卡报表</x:Name>
"
);
sb.Append(
"
<x:WorksheetOptions>
"
);
sb.Append(
"
<x:Print>
"
);
sb.Append(
"
<x:ValidPrinterInfo/>
"
);
sb.Append(
"
</x:Print>
"
);
sb.Append(
"
</x:WorksheetOptions>
"
);
sb.Append(
"
</x:ExcelWorksheet>
"
);
sb.Append(
"
</x:ExcelWorksheets>
"
);
sb.Append(
"
</x:ExcelWorkbook>
"
);
sb.Append(
"
</xml>
"
);
sb.Append(
"
<![endif]-->
"
);
sb.Append(
"
</head>
"
);
sb.Append(
"
<body>
"
);
sb.Append(strData);
sb.Append(
"
</body>
"
);
sb.Append(
"
</html>
"
);
//
====================================================
WriteExcelFile(HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationSettings.AppSettings[
"
path_excel
"
].ToString().Trim())
+
strFileName,sb.ToString());
//
====================================================
return
System.Configuration.ConfigurationSettings.AppSettings[
"
path_excel
"
].ToString().Trim()
+
strFileName;
}
/**/
///
<summary>
///
写Excel文件
///
</summary>
///
<param name="strFileName"></param>
///
<param name="strData"></param>
private
void
WriteExcelFile(
string
strFileName,
string
strData)
{
try
{
StreamWriter sw
=
new
StreamWriter(strFileName,
true
,System.Text.Encoding.Default);
sw.WriteLine(strData);
sw.Close();
}
catch
(Exception e)
{
string
str
=
e.Message;
}
}
查看全文
相关阅读:
电脑无法开机,用一个U盘先备份C盘部分重要文件并重装Win10系统的教程?
如何用WINPE备份电脑系统;电脑备份 听语音
如何使用ghost备份系统?
编程之美初赛第一场 活动中心
从拟物到简约 ------谈站点设计风格的变革
算法之回溯思想
【工业串口和网络软件通讯平台(SuperIO)教程】一.通讯机制
为什么要使用CMake+VS编译OpenCV的源代码
Json实现异步请求(提交评论)
kendo AutoComplete实现多筛选条件
原文地址:https://www.cnblogs.com/ding0910/p/556829.html
最新文章
一套oracle的练习题
OGG实现两台Oracle数据库的同步
分布式存储和集中式存储的优缺点及选择
[NOI2015]软件包管理器
CF311E Biologist
[CEOI2008]order
[SHOI2007]善意的投票
【模板】最长公共子序列
骑士共存问题
[USACO08FEB]酒店Hotel
热门文章
[NOIP2017] 宝藏
[NOIP2017] 逛公园
luogu P3398 仓鼠找sugar
更新索引库: $locate string 寻找包含有string的路径: $updatedb
查看当前目录下文件个数: $find ./ | wc -l
选择“保留window设置、个人文件及应用”或者“升级安装windows并保留文件设置和应用程序”的 处理干净以后用ghost备份
通用PE u盘装Ghost Win7系统教程
怎么用优启通安装win7 !!!!好好好20191020
U盘PE重装系统导致D、E、F盘消失
优启通-PE启动盘制作工具 原版Win7系统安装超详细教程!!!!!
Copyright © 2011-2022 走看看