MFC 创建HTML格式数据并显示
2009-07-14 09:50
471 查看
typedef vector<CStringW> FileLines;
typedef vector<CStringW> HeadNameHtml;
typedef vector<CStringW> RowValue;
typedef map<int, RowValue> TableValueHtml;
//输出数据到临时文件,返回文件全名
CStringW OutputHtmlW(FileLines lineInfo, CStringW wcsFileName)
{
FileLines::iterator ite;
wchar_t wcsPath[MAX_PATH];
wchar_t wcsLogFileName[MAX_PATH];
memset(wcsPath, 0, sizeof(wcsPath));
memset(wcsLogFileName, 0, sizeof(wcsLogFileName));
GetModuleFileNameW(NULL, wcsPath, sizeof(wcsPath));//取得exe全名称
wchar_t* pwcsEnd = wcsrchr(wcsPath,'//');
pwcsEnd++;
*pwcsEnd = '/0';
wcscat(wcsPath, wcsFileName);
std::wofstream output(wcsPath, ios::trunc);
output.imbue(locale("chs") ); //设定当前编码为中文
for (ite = lineInfo.begin(); ite != lineInfo.end(); ite++)
{
output << (const wchar_t*)(*ite);
output << endl;
}
output.close();
return CStringW(wcsPath);
}
//将要显示的内容转换为html格式的数据
FileLines CreateHtmlContext(HeadNameHtml headNames, TableValueHtml items)
{
CStringW wcsInfo(L"");
CStringW wcsFileName((L"Report.html"));
CStringW wcsFullName;
TableValueHtml::iterator ite;
FileLines lines;
int iloop = 0;
int iItemsCount = items.size();
int iColumnCount = headNames.size();
lines.insert(lines.end(), L"<html>");
lines.insert(lines.end(), L" <title></title>");
lines.insert(lines.end(), L" <head> ");
lines.insert(lines.end(), L" <table border = 1> ");
lines.insert(lines.end(), L" <tr> ");
for (; iloop < iColumnCount; iloop++) {
lines.insert(lines.end(), L" <th> ");
lines.insert(lines.end(), headNames[iloop]);
lines.insert(lines.end(), L" ");
lines.insert(lines.end(), L" <th> ");
}
lines.insert(lines.end(), L" <tr> ");
for(ite = items.begin(); ite != items.end(); ite++) {
lines.insert(lines.end(), L" <tr> ");
for (iloop = 0; iloop < iColumnCount; iloop++) {
lines.insert(lines.end(), L" <td> ");
CStringW value = (*ite).second[iloop];
lines.insert(lines.end(), value);
lines.insert(lines.end(), L" ");
lines.insert(lines.end(), L" <td> ");
}
lines.insert(lines.end(), L" <tr> ");
}
lines.insert(lines.end(), L" </table> ");
lines.insert(lines.end(), L" </head>");
lines.insert(lines.end(), L"</html>");
return lines;
}
/*应用上面的两个函数将指定的内容在html中以表格的方式显示
void ShowHtmlFile()
{
CStringW wcsFullName;
CStringW wcsFileName(L"Report.html");//创建的文件名称
TableValueHtml items; //要显示的内容
HeadNameHtml headNames ;//表标题
.
. ~添加内容到items, headNames~
.
.
FileLines lines = CreateHtmlContext(headNames, items);//将要显示的内容转换为html格式的数据
wcsFullName = OutputHtmlW(lines, wcsFileName); //输出数据到临时文件,返回文件全名
ShellExecute(NULL, L"Open", L"IEXPLORE.EXE", wcsFullName, NULL, SW_SHOWNORMAL);//用浏览器显示文件
}
typedef vector<CStringW> HeadNameHtml;
typedef vector<CStringW> RowValue;
typedef map<int, RowValue> TableValueHtml;
//输出数据到临时文件,返回文件全名
CStringW OutputHtmlW(FileLines lineInfo, CStringW wcsFileName)
{
FileLines::iterator ite;
wchar_t wcsPath[MAX_PATH];
wchar_t wcsLogFileName[MAX_PATH];
memset(wcsPath, 0, sizeof(wcsPath));
memset(wcsLogFileName, 0, sizeof(wcsLogFileName));
GetModuleFileNameW(NULL, wcsPath, sizeof(wcsPath));//取得exe全名称
wchar_t* pwcsEnd = wcsrchr(wcsPath,'//');
pwcsEnd++;
*pwcsEnd = '/0';
wcscat(wcsPath, wcsFileName);
std::wofstream output(wcsPath, ios::trunc);
output.imbue(locale("chs") ); //设定当前编码为中文
for (ite = lineInfo.begin(); ite != lineInfo.end(); ite++)
{
output << (const wchar_t*)(*ite);
output << endl;
}
output.close();
return CStringW(wcsPath);
}
//将要显示的内容转换为html格式的数据
FileLines CreateHtmlContext(HeadNameHtml headNames, TableValueHtml items)
{
CStringW wcsInfo(L"");
CStringW wcsFileName((L"Report.html"));
CStringW wcsFullName;
TableValueHtml::iterator ite;
FileLines lines;
int iloop = 0;
int iItemsCount = items.size();
int iColumnCount = headNames.size();
lines.insert(lines.end(), L"<html>");
lines.insert(lines.end(), L" <title></title>");
lines.insert(lines.end(), L" <head> ");
lines.insert(lines.end(), L" <table border = 1> ");
lines.insert(lines.end(), L" <tr> ");
for (; iloop < iColumnCount; iloop++) {
lines.insert(lines.end(), L" <th> ");
lines.insert(lines.end(), headNames[iloop]);
lines.insert(lines.end(), L" ");
lines.insert(lines.end(), L" <th> ");
}
lines.insert(lines.end(), L" <tr> ");
for(ite = items.begin(); ite != items.end(); ite++) {
lines.insert(lines.end(), L" <tr> ");
for (iloop = 0; iloop < iColumnCount; iloop++) {
lines.insert(lines.end(), L" <td> ");
CStringW value = (*ite).second[iloop];
lines.insert(lines.end(), value);
lines.insert(lines.end(), L" ");
lines.insert(lines.end(), L" <td> ");
}
lines.insert(lines.end(), L" <tr> ");
}
lines.insert(lines.end(), L" </table> ");
lines.insert(lines.end(), L" </head>");
lines.insert(lines.end(), L"</html>");
return lines;
}
/*应用上面的两个函数将指定的内容在html中以表格的方式显示
void ShowHtmlFile()
{
CStringW wcsFullName;
CStringW wcsFileName(L"Report.html");//创建的文件名称
TableValueHtml items; //要显示的内容
HeadNameHtml headNames ;//表标题
.
. ~添加内容到items, headNames~
.
.
FileLines lines = CreateHtmlContext(headNames, items);//将要显示的内容转换为html格式的数据
wcsFullName = OutputHtmlW(lines, wcsFileName); //输出数据到临时文件,返回文件全名
ShellExecute(NULL, L"Open", L"IEXPLORE.EXE", wcsFullName, NULL, SW_SHOWNORMAL);//用浏览器显示文件
}
相关文章推荐
- jsp中从数据库得数据的显示格式控制和html超链接传值写法
- Android中将带html格式的数据转换成java识别显示内容
- ASP.net 从数据库中读取html格式的数据并显示在页面中
- Json格式数据HTML页面中格式化显示,可折叠,可展开
- velocity 如何使用webx3+velocity显示html格式数据 转义尖括号
- 在MFC中显示html数据
- MFC显示Mat数据格式(Opencv)图片,保证4字节对齐,图片缩放不错行
- MFC显示Mat数据格式(Opencv)图片,保证4字节对齐,图片缩放不错行
- 如何用TextView显示Html格式的数据
- django之创建第8-1个项目-数据库之增删改查/数据库数据显示在html页面
- [Ajax]便于在html页面中引用javascript显示后台数据的一段ajax代码
- 导航程序调试1---MFC应用以及数据显示程序
- Android解析后台给的Html格式的图文结合的数据,只需一个TextView就能展示。
- PDF Form (2) --- 创建显示任意多行数据的动态Table
- ORACLE SQL 查询数据库 数据显示的格式设置
- C#+ArcEngine 不同格式数据打开,对象创建,导入导出
- MFC学习笔记(四)- 模态对话框与非模态对话框的创建与显示
- sql长日期数据以短日期格式显示
- 不需要存入文件,直接将获取的数据转换成甘特图所需的数据格式并显示
- 使用 UITableView 创建表格应用——从plist文件加载并显示数据(转)