今天写的一个导出html页面的过程
private string ExportHtml()
{
string msg = "";
try
{
#region
string fileName = Application.StartupPath + "\\模板\\template.htm";//模板路径
DataTable tb = SqlModel.Query("SELECT A.*,B.DD0022_002,ISNULL(X.DD0022_002,'')AS 股票代码,ISNULL(X.DD0022_002,'')AS 债券代码,ISNULL(Y.DD0022_002,'')AS 港股 FROM(SELECT DISTINCT A.NEWSCODE AS 新闻编码,A.NW0001_002 AS 文章标题," +
"A.NW0001_003 AS 文章正文,A.NW0001_004 AS 媒体来源,B.ITCODE AS ITCODE,C.ITNAME AS ITNAME " +
"FROM CMBDB.DBO.CSNW0003 A INNER JOIN(SELECT NEWSCODE,INDICATORSCODE,ITCODE FROM CMBDB.DBO.CSNW0002 )B " +
"ON A.NEWSCODE = B.NEWSCODE LEFT JOIN(SELECT * FROM DD0006) C ON B.ITCODE = C.ITCODE WHERE B.INDICATORSCODE<>'90101' AND A.NW0001_001='" + DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00.000' AND A.ENTRYTIME<='09:00:00' " +
")A LEFT JOIN(SELECT SENAME,DD0022_002,ITCODE FROM(SELECT SENAME,DD0022_002,ITCODE,ROW_NUMBER()OVER(PARTITION BY ITCODE ORDER BY DD0022_002 ASC) AS RANK FROM " +
"(SELECT SECODE,SENAME FROM BASICDB.DBO.DD0007 WHERE DD0007_002='1' AND DD0007_004 IN (101,102) )A LEFT JOIN " +
"DD0011 B ON A.SECODE=B.SECODE LEFT JOIN DD0009 C " +
"ON B.SECODE=C.SECODE LEFT JOIN DD0022 D ON C.TRCODE=D.SECODE WHERE DD0022_001 ='5000' )Z WHERE RANK=1)B ON A.ITCODE=B.ITCODE LEFT JOIN(SELECT ITCODE,DD0022_002 FROM(SELECT * FROM DD0011) A " +
"LEFT JOIN DD0009 B ON A.SECODE=B.SECODE LEFT JOIN DD0022 C ON B.TRCODE=C.SECODE WHERE A.SECODE LIKE '104%' AND DD0022_001='5000' AND MKCODE IN (1,2))X ON X.ITCODE=B.ITCODE " +
"LEFT JOIN(SELECT ITCODE,DD0022_002 FROM(SELECT * FROM DD0011 WHERE LEFT(SECODE,3)='101')A LEFT JOIN(SELECT * FROM DD0009 WHERE LEFT(TRCODE,3)='201')B ON A.SECODE=B.SECODE " +
"LEFT JOIN(SELECT * FROM DD0022 WHERE DD0022_001='5000' AND MKCODE='3')C ON B.TRCODE=C.SECODE)Y ON Y.ITCODE=A.ITCODE");//类型1的信息
string html = string.Empty;//所有的html;
string titlelink1 = string.Empty;//上市公司及债券人标题链接
string ArticleContent1 = string.Empty;//上市公司及债券人内容
string titlelink2 = string.Empty;//其他机构标题链接
string ArticleContent2 = string.Empty;//其他机构内容
string titlelink3=string.Empty;//行业标题连接
string ArticleContent3=string.Empty;//行业内容
string ArticleContent33=string.Empty;//行业内容
string code = "";
string reasset = "";
string sort = "";
string content = "";
int itcount = 0;
int newscount = 0;
Hashtable ht = new Hashtable();
#endregion
#region
itcount = tb.Rows.Count;
for (int i = 0; i < tb.Rows.Count; i++)
{
if (tb.Rows[i]["DD0022_002"].ToString() == "" && tb.Rows[i]["港股"].ToString() == "")
continue;
code = tb.Rows[i][0].ToString();
if (ht.Contains(code))
{
continue;
}
else
{
ht.Add(code, i);
}
newscount += 1;
titlelink1 += "<li class='li'><a class='ctitle' href='#a" + newscount + "'>" + tb.Rows[i][1].ToString() + "</a></li>";
ArticleContent1 += @"<table width='100%' border='0' align='center' cellpadding='0' cellspacing='0' style='margin-top:0px;border-bottom:#CCC solid 1px;'>
<tr>
<td colspan='3'>
<div class='ArticleTitle'>
<div style='margin:10px auto 1px;'><a name='a" + newscount + "'></a>" + tb.Rows[i][1].ToString() + @"</div>
<div style='margin:0px; font-size:12px; color:#404040; font-weight:normal;'>来源:" +tb.Rows[i][3].ToString()+@"
</div>
<div style='background:url(images/line.gif) no-repeat; width:749px; height:1px;'></div>
</div>
</td></tr>
<tr>
<td colspan='3'class='paragraph'>"+tb.Rows[i][2].ToString()+@"
</td>
</tr>
<tr>
<td width='187'> </td>
<td width='187'> </td>
<td width='382' align='right'><a href='#_Top'><img src='images/top.gif' width='48' height='17'></a></td>
</tr>
</table>";
}
StreamReader sr = new StreamReader(fileName, System.Text.Encoding.GetEncoding("utf-8"));
html = sr.ReadToEnd();
html=html.Replace("<!--上市公司及债券人link-->", titlelink1);
html=html.Replace("<!--上市公司及债券人Content-->", ArticleContent1);
string path = Application.StartupPath + "\\temp\\负面信息监控早报" + DateTime.Now.ToString("yyyyMMdd") + ".htm";
#endregion
#region
itcount = tb.Rows.Count;
for (int i = 0; i < tb.Rows.Count; i++)
{
if (tb.Rows[i]["DD0022_002"].ToString() != "" || tb.Rows[i]["港股"].ToString() != "")
continue;
code = tb.Rows[i][0].ToString();
if (ht.Contains(code))
{
continue;
}
else
{
ht.Add(code, i);
}
newscount += 1;
titlelink2 += "<li class='li'><a class='ctitle' href='#a" + newscount + "'>" + tb.Rows[i][1].ToString() + "</a></li>";
ArticleContent2 += @"<table width='100%' border='0' align='center' cellpadding='0' cellspacing='0' style='margin-top:0px;border-bottom:#CCC solid 1px;'>
<tr>
<td colspan='3'>
<div class='ArticleTitle'>
<div style='margin:10px auto 1px;'><a name='a" + newscount + "'></a>" + tb.Rows[i][1].ToString() + @"</div>
<div style='margin:0px; font-size:12px; color:#404040; font-weight:normal;'>来源:" + tb.Rows[i][3].ToString() + @"
</div>
<div style='background:url(images/line.gif) no-repeat; width:749px; height:1px;'></div>
</div>
</td></tr>
<tr>
<td colspan='3'class='paragraph'>" + tb.Rows[i][2].ToString() + @"
</td>
</tr>
<tr>
<td width='187'> </td>
<td width='187'> </td>
<td width='382' align='right'><a href='#_Top'><img src='images/top.gif' width='48' height='17'></a></td>
</tr>
</table>";
}
html=html.Replace("<!--其他机构link-->", titlelink2);
html=html.Replace("<!--其他机构Content-->", ArticleContent2);
#endregion
#region 行业
string hysql = @"select distinct
a.NewsCode as 新闻编码,
a.NW0001_002 as 文章标题,
a.NW0001_003 as 文章正文,
a.NW0001_004 as 媒体来源,
DD0003_006,
case when DD0003_006='地区分类' then REGIONNAME
when DD0003_006='国标行业分类' then c.industryname
end as abc,
g.industryname,
a.NW0001_001 as 发布时间,
a.ENTRYTIME as 时间
from
CMBDB.DBO.csnw0003 A
inner join
(select NewsCode, NW0006_001,NW0006_002 from CMBDB.DBO.csnw0006
where NW0006_001 not in (2)
)B
on a.newscode = b.newscode
left join
(
select industrycode,industryname from basicdb.dbo.dd0025 where dd0025_003='9' and dd0025_004='1'
union all
select '254545690','电力、燃气及水的生产和供应业'
union all
select a.industrycode,b.industryname from
(select industrycode,industryname,dd0025_004,industrycode2 from basicdb.dbo.dd0025 where dd0025_003='9' and dd0025_004='2' and industrycode<>'254545690')a
left join
(select industrycode,industryname,dd0025_004,industrycode2 from basicdb.dbo.dd0025 where dd0025_003='9' and dd0025_004='1')b
on a.industrycode2=b.industrycode
union all
select a.industrycode,c.industryname from
(select industrycode,industryname,dd0025_004,industrycode2 from basicdb.dbo.dd0025 where dd0025_003='9' and dd0025_004='3' and industrycode not in ('254545637','254545622'))a
left join
(select industrycode,industryname,dd0025_004,industrycode2 from basicdb.dbo.dd0025 where dd0025_003='9' and dd0025_004='2')b
on a.industrycode2=b.industrycode
left join
(select industrycode,industryname,dd0025_004,industrycode2 from basicdb.dbo.dd0025 where dd0025_003='9' and dd0025_004='1')c
on c.industrycode=b.industrycode2
) c
on b.NW0006_002 = cast(c.industrycode as varchar(max))
LEFT JOIN
(SELECT * FROM CMBDB.DBO.DD0003 WHERE DD0003_001 = 152 AND DD0003_005 IN ('1','3'))D
ON D.DD0003_005=B.NW0006_001
LEFT JOIN
(SELECT * FROM CMBDB.DBO.CSNW0006 WHERE NW0006_001='1')E
ON E.NEWSCODE=A.NEWSCODE
LEFT JOIN
(SELECT * FROM basicdb.dbo.DD0020)F
ON E.nw0006_002=F.REGIONCODE
left join
(select * from basicdb.dbo.dd0025) g
on b.NW0006_002 = g.industrycode
where a.NW0001_001='" + DateTime.Now.ToString("yyyy-MM-dd") + @" 00:00:00.000' and a.ENTRYTIME<='09:00:00' and a.examine='1' ---and nw0006_001=3
and DD0003_006 is not null and DD0003_006<>'地区分类'";//类型3的信息
tb = SqlModel.Query(hysql);
List<string> listhyfl = new List<string>();
foreach (DataRow drhyfl in tb.Rows)//检索出所有的行业大类放到一个list集合中
{
if (!listhyfl.Contains(drhyfl["abc"].ToString()))
listhyfl.Add(drhyfl["abc"].ToString());
}
ht.Clear();
int icount = 0;
foreach (string hyfl in listhyfl)//新修改按行业分类输出、行业类型作为二级、标题为三级--ljc
{
icount += 1;
ArticleContent33="";
titlelink3+="<div style='margin:2px 4px 0px;'><a class='ctype' href='#toc001'> 【"+hyfl+"】</a></div><ul style='color: #CCC; margin:0px auto 0px;'>";
ArticleContent3+=@" <tr>
<td width='5'></td>
<td height='5' colspan='2'>
<div class='"+(icount==1?"typehead":"typehead1")+@"'></div>
</td>
</tr><tr>
<td style='padding:0px;'><img src='images/ProductType1.gif' width='5' height='40' border='0'/></td>
<td width='30%' style='white-space:nowrap;'><div style='background:url(images/ProductType2.gif) repeat-x; width:auto; color:#FFF; font-family:Arial, Helvetica, sans-serif 14px; height:38px; width:50px; padding-top:8px;'> " + hyfl + @" </div></td>
<td width='65%' style='border-right:#CCC solid 1px;'> </td>
</tr>
<tr>
<td></td>
<td colspan='2'>
<div class='ArticleContent1'>
<!--Content3-->
</div>
</td>
</tr>
";
DataRow[] drSelect = tb.Select("abc='" + hyfl + "'");
for (int i = 0; i < drSelect.Length; i++)
{
code = drSelect[i][0].ToString();
//if (ht.Contains(code))
//{
// continue;
//}
//else
//{
// ht.Add(code, i);
//}
sort = drSelect[i][4].ToString();
newscount += 1;
if (sort == "国标行业分类")
{
reasset = drSelect[i]["industryname"].ToString();
sort = "国内-行业";
}
else if (sort == "地区分类")
{
if (drSelect[i]["industryname"].ToString() == "香港")
{
sort = "香港-行业";
}
else
{
sort = "国内-行业";
}
reasset = drSelect[i][5].ToString();
}
titlelink3+="<li class='li'><a class='ctitle' href='#a"+newscount+"'>"+drSelect[i][1].ToString()+"</a></li>";
ArticleContent33 += @"<table width='100%' border='0' align='center' cellpadding='0' cellspacing='0' style='margin-top:0px;border-bottom:#CCC solid 1px;'>
<tr>
<td colspan='3'>
<div class='ArticleTitle1'>
<div style='margin:10px auto 1px;'><a name='a" + newscount + "'></a>" + drSelect[i][1].ToString() + @"</div>
<div style='margin:0px; font-size:12px; color:#404040; font-weight:normal;'>来源:" + drSelect[i][3].ToString() + " 分类:" + sort + " 关联资产:" + reasset + @"
</div>
<div style='background:url(images/line.gif) no-repeat; width:749px; height:1px;'></div>
</div>
</td></tr>
<tr>
<td colspan='3' class='paragraph'>" + drSelect[i][2].ToString() + @"</td>
</tr>
<tr>
<td width='187'> </td>
<td width='187'> </td>
<td width='382' align='right'><a href='#_Top'><img src='images/top.gif' width='48' height='17'></a></td>
</tr>
</table>";
}
titlelink3 += "</ul>";
ArticleContent3 = ArticleContent3.Replace(" <!--Content3-->", ArticleContent33);
}
html=html.Replace("<!--行业link-->", titlelink3);
html=html.Replace("<!--行业Content-->", ArticleContent3);
html = html.Replace("<a name=\"_Top\"></a><span class=\"date\" >2011-07-28", "<a name=\"_Top\"></a><span class=\"date\" >"+DateTime.Now.ToString("yyyy年MM月dd日"));
path = Application.StartupPath + "\\temp\\负面信息监控早报" + DateTime.Now.ToString("yyyyMMdd") + ".htm";
if (!File.Exists(path))
{
using (StreamWriter sw = File.CreateText(path))
{
sw.Write(html);
}
}
else
{
FileStream fs = File.Open(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
using (StreamWriter sw =new StreamWriter(fs))
{
sw.Write(html);
}
}
//newDbInput.Mail.Preview review = new newDbInput.Mail.Preview(html);
//review.Show();
#endregion
msg = "导出成功!";
}
catch (Exception ex)
{
msg = ex.Message;
}
return msg;
}
}
转载于:https://www.cnblogs.com/lijinchang/archive/2011/07/27/2118530.html
今天写的一个导出html页面的过程相关推荐
- 给定一个n节点的二叉树,写出一个O(n)时间递归过程,将该树每个节点关键字输出(算法导论第十章10.4-2)
给定一个n节点的二叉树,写出一个O(n)时间递归过程,将该树每个节点关键字输出 (算法导论第十章10.4-2) #include <iostream> template<typena ...
- 用OleDb写的一个导出Excel的方法
为什么80%的码农都做不了架构师?>>> //前几天遇到个导出Excel的问题,然后上网找了很久,终于写出这个方法了,所以分享一下. /// <summary> / ...
- 用java编写一个微博登陆页面
上次也写了一个微博登陆页面,不过功能还不够完善.今天重新完善了一些功能,分享出来给大家. 基本功能如下: (1)具有类似新浪微博的用户注册图形界面. (2)使用用户名或手机号注册,注册时需要提供新密码 ...
- 分享下自己写的一个微信小程序请求远程数据加载到页面的代码
分享下自己写的一个微信小程序请求远程数据加载到页面的代码 1 思路整理 就是页面加载完毕的时候 请求远程接口,然后把数据赋值给页面的变量 ,然后列表循环 2 js相关代码 我是改的 onload ...
- html导航栏重叠怎么办,请问前端大神,html如何引入另一个html,写了一个导航栏想在多个页面中如何重复使用?...
写了一个头部导航栏的html 想在多个html页面中引用,请问怎么操作? 网上找了用标签 实际效果并不好 , 导航栏中按钮下拉菜单无法完全显示 请问大牛们平时开发中怎么处理这个的 如图 : 可以使用 ...
- 从一个页面跳转到用swiper写的全屏滚动页面的指定位置
问题背景 从一个页面跳转到用swiper写的全屏滚动页面的指定位置,怎么实现啊? 案例 我没有自己写一个全屏滚动,就在Swiper官网找了Swiper在PC端的全屏页面效果展示 若有侵权请留言告知我更 ...
- 写一个静态HTML页面,直接写HTML代码和用JS动态生成代码,哪种方式要好
如果写一个静态HTML页面,直接写HTML代码和用JS动态生成代码,哪种方式要好点?为什么? 不考虑人力因素(手写HTML太费时间排除),请从读取和解析或者其他的角度分析.谢谢 添加评论 分享 按投票 ...
- 用HTML写一个超级课程表页面
用HTML写一个超级课程表页面 首先给大家展示一下效果图,他家可以根据自己的喜好,换成自己喜欢的颜色 看到这个图可以把它肯成一个大的表格来进行做,将一些单元格进行相应的合并就可以达到上面所期望的图片效 ...
- 写出一个抽奖页面,有200个人参加抽奖
写出一个抽奖页面 有200个人参加抽奖,每次抽出一个人,不能重复,必须每个人都要抽中奖 前面10次抽奖要选中固定的10个人,每次就从这10人中随机抽取一人,不能重复 从第11次开始就从剩余的190人当 ...
- 给女朋友做一个html页面,某程序员写给女友的清新页面
[javascript]代码库/* 网上发现了一个某程序员写给女友的清新页面 项目主页:http://love.hackerzhou.me */ // variables var $window = ...
最新文章
- jmeter linux安装,Linux下安装Jmeter
- 【网络安全】Windows恶意软件BazarLoader分析
- PM应该找哪些副业?
- 当Elasticsearch遇见智能客服机器人
- Linux查看负载 uptime,w ,top,iostat 命令
- Linux学习笔记---boot命令的使用
- C#中IQueryable和IEnumberable的区别
- 使用ajax的时候必须要加的几行代码
- MetadataReader、ClassMetadata、AnnotationMetadata的简单使用
- thinkpad x230 换三星 msata ssd 860 EVO
- 网络安全实验室-脚本关1-15
- python pandas安装不了_python安装pandas问题!python pandas安装教程
- drm android 工作原理,[原创]某DRM解密流程简单分析
- java clh_Java多线程编程CLH锁详解
- 2022年4月23日美团笔试
- 利用Python在环境气象海洋领域实现基础计算与绘图
- 频域串联滞后校正matlab,基于MATLAB的串联超前校正、滞后校正和串联滞后-超前校正设计.pdf...
- win7系统下联想thinkpad x220笔记本电脑关闭触摸板
- 【手机号验证/前端】Vue2+elementUI编写一个手机号验证码登录页面,路由式开发(附完整代码)
- ESP32 Ubuntu开发环境搭建
热门文章
- 小D课堂 - 零基础入门SpringBoot2.X到实战_第11节 Logback日志框架介绍和SpringBoot整合实战_45、SpringBoot2.x日志讲解和Logback配置实战...
- 小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_40、Redis工具类封装讲解和实战...
- 阶段3 2.Spring_06.Spring的新注解_2 spring的新注解-Bean
- 关于select标签曾经踩过的几个坑!
- spring jpa查询视图
- [RMQ] [线段树] POJ 3368 Frequent Values
- Hibernate HQL详解
- Lesson 73-74 The quality of our lives
- 学习笔记:工厂方法模式及简单工厂模式的对比
- 使用npm安装vue项目+使用