博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Qt-读取文本导出word
阅读量:4972 次
发布时间:2019-06-12

本文共 12008 字,大约阅读时间需要 40 分钟。

代码:

1 #include "FileOpeartion.h"  2   3   4 FileOpeartion::FileOpeartion (void)  5 {  6 }  7   8   9 QVector
FileOpeartion::GetTheSimulationRecord() 10 { 11 QVector
simTempList ; 12 return simTempList; 13 } 14 15 // lyy : 2016/8/26 16:40:11 说明:读取文本 16 bool FileOpeartion:: GetTheTextContent (const QString strPath, QStringList &strContent) 17 { 18 QFile file (strPath); 19 20 if (file.open (QIODevice::ReadOnly | QIODevice::Text)) 21 { 22 QTextStream in (&file); 23 //in.setCodec (QTextCodec::codecForName ("GB2312")); 24 QString line; 25 26 while (!in.atEnd()) 27 { 28 line = in.readLine(); 29 30 if (!line.isNull() && !line.isEmpty()) 31 { 32 strContent << line; 33 } 34 } 35 36 file.close(); 37 } 38 39 return true; 40 } 41 QString FileOpeartion::GetTheTextHtml (const QString strPath) 42 { 43 QString strContent; 44 strContent.append (""); 45 strContent.append (""); 46 strContent.append ("
"); 47 strContent.append (""); 48 strContent.append ("
"); 49 strContent.append ("
"); 50 strContent.append ("
"); 53 strContent.append ("
"); 56 strContent.append ("
"); 57 strContent.append ("
"); 58 strContent.append ("
"); 59 strContent.append ("
"); 60 strContent.append ("
"); 61 strContent.append ("
");195 strContent.append ("
");196 strContent.append ("
");197 strContent.append ("
");198 strContent.append ("
");199 strContent.append ("
");200 strContent.append ("
");201 strContent.append ("
");202 strContent.append ("
");203 strContent.append ("
值班员:"); 51 strContent.append ("");//replace one 52 strContent.append (" 日期 :"); 54 strContent.append ("");//replace two 55 strContent.append ("
空 间 环 境 预 报 和 警 报
"); 62 strContent.append ("
"); 63 strContent.append ("
"); 64 strContent.append ("
"); 67 strContent.append ("
"); 70 strContent.append ("
"); 73 strContent.append ("
"); 74 strContent.append ("
"); 75 strContent.append ("
"); 76 strContent.append ("
"); 77 strContent.append ("
"); 80 strContent.append ("
"); 83 strContent.append ("
"); 86 strContent.append ("
"); 87 strContent.append ("
"); 88 strContent.append ("
"); 89 strContent.append ("
"); 92 strContent.append ("
"); 95 strContent.append ("
"); 98 strContent.append ("
"); 99 strContent.append ("
");100 strContent.append ("
");101 strContent.append ("
");104 strContent.append ("
");107 strContent.append ("
");110 strContent.append ("
");111 strContent.append ("
");112 strContent.append ("
");113 strContent.append ("
");116 strContent.append ("
");119 strContent.append ("
");122 strContent.append ("
");123 strContent.append ("
");124 strContent.append ("
");125 strContent.append ("
");128 strContent.append ("
");131 strContent.append ("
");134 strContent.append ("
");135 strContent.append ("
");136 strContent.append ("
");137 strContent.append ("
");140 strContent.append ("
");143 strContent.append ("
");146 strContent.append ("
");147 strContent.append ("
");148 strContent.append ("
");149 strContent.append ("
");152 strContent.append ("
");155 strContent.append ("
");158 strContent.append ("
");159 strContent.append ("
");160 strContent.append ("
");161 strContent.append ("
");164 strContent.append ("
");167 strContent.append ("
");170 strContent.append ("
");171 strContent.append ("
");172 strContent.append ("
");173 strContent.append ("
");176 strContent.append ("
");177 strContent.append ("
");178 strContent.append ("
");179 strContent.append ("
");182 strContent.append ("
");183 strContent.append ("
");184 strContent.append ("
");185 strContent.append ("
");188 strContent.append ("
");189 strContent.append ("
");190 strContent.append ("
");191 strContent.append ("
");193 strContent.append ("
");194 strContent.append ("
项目 "); 65 strContent.append ("");//repalce three 66 strContent.append (" "); 68 strContent.append ("");//repalce three 69 strContent.append (" "); 71 strContent.append ("");//repalce three 72 strContent.append ("
太阳10.7cm流量 "); 78 strContent.append (""); 79 strContent.append (" "); 81 strContent.append (""); 82 strContent.append (" "); 84 strContent.append (""); 85 strContent.append ("
太阳M级X耀斑概率 "); 90 strContent.append (""); 91 strContent.append (" "); 93 strContent.append (""); 94 strContent.append (" "); 96 strContent.append (""); 97 strContent.append ("
太阳X级X耀斑概率 ");102 strContent.append ("");103 strContent.append (" ");105 strContent.append ("");106 strContent.append (" ");108 strContent.append ("");109 strContent.append ("
太阳质子事件发生概率 ");114 strContent.append ("");115 strContent.append (" ");117 strContent.append ("");118 strContent.append (" ");120 strContent.append ("");121 strContent.append ("
高能电子增强事件概率 ");126 strContent.append ("");127 strContent.append (" ");129 strContent.append ("");130 strContent.append (" ");132 strContent.append ("");133 strContent.append ("
地磁Ap指数 ");138 strContent.append ("");139 strContent.append (" ");141 strContent.append ("");142 strContent.append (" ");144 strContent.append ("");145 strContent.append ("
小地磁暴发生概率 ");150 strContent.append ("");151 strContent.append (" ");153 strContent.append ("");154 strContent.append (" ");156 strContent.append ("");157 strContent.append ("
大地磁暴发生概率 ");162 strContent.append ("");163 strContent.append (" ");165 strContent.append ("");166 strContent.append (" ");168 strContent.append ("");169 strContent.append ("
空间环境综述: ");174 strContent.append ("");175 strContent.append ("
空间环境形势: ");180 strContent.append ("");181 strContent.append ("
空间环境警报: ");186 strContent.append ("");187 strContent.append ("
备注: ");192 strContent.append ("
 
中国科学院空间环境研究预报中心
中国科学院国家空间科学中心
");204 strContent.append ("");205 strContent.append ("");206 strContent.append ("");207 strContent.append ("");208 strContent.append ("");209 strContent.append ("");210 strContent.append ("");211 strContent.append ("");212 strContent.append ("");213 strContent.append ("");214 strContent.append ("");215 strContent.append ("");216 strContent.append ("");217 strContent.append ("");218 strContent.append ("");219 strContent.append ("");220 strContent.append ("");221 strContent.append ("");222 strContent.append ("");223 strContent.append ("");224 strContent.append ("");225 strContent.append ("");226 strContent.append ("");227 strContent.append ("");228 strContent.append ("");229 strContent.append ("");230 strContent.append ("");231 strContent.append ("");232 strContent.append ("");233 strContent.append ("");234 strContent.append ("");235 strContent.append ("");236 strContent.append ("");237 strContent.append ("");238 strContent.append ("");239 strContent.append ("");240 strContent.append ("");241 strContent.append ("");242 strContent.append ("");243 strContent.append ("");244 strContent.append ("");245 strContent.append ("");246 strContent.append ("");247 strContent.append ("");248 strContent.append ("");249 strContent.append ("");250 strContent.append ("");251 strContent.append ("");252 strContent.append ("");253 strContent.append ("");254 strContent.append ("");255 // QFile file (strPath);256 //if (file.open (QIODevice::ReadOnly | QIODevice::Text))257 //{258 // QTextStream in (&file);259 // //in.setCodec (QTextCodec::codecForName ("GB2312"));260 // QString line;261 //262 // while (!in.atEnd())263 // {264 // line = in.readLine();265 //266 // if (!line.isNull() && !line.isEmpty())267 // {268 // strContent.append (line);269 // }270 // }271 //272 // file.close();273 //}274 return strContent;275 }276 277 QStringList FileOpeartion::GetThePicList (const QString strPath, QDateTime dt)278 {279 QStringList strTempList;280 QFile dataFile (strPath);281 282 if (dataFile.open (QIODevice::ReadOnly | QIODevice::Text))283 {284 QTextStream in (&dataFile);285 QString line;286 // bool isNull = true;287 QString tmp = dt.toString ("yyyyMMdd hh:mm:ss");288 289 while (!in.atEnd())290 {291 line = in.readLine();292 /*QRegExp rx("^[# | :].*");*/293 QRegExp rx1 ("^#");294 QRegExp rx2 ("^:");295 296 if (line.indexOf (rx1) >= 0 || line.indexOf (rx2) >= 0)297 {298 continue;299 }300 301 else302 {303 QStringList pics = line.split ("/");304 305 if (pics.count() < 4)306 {307 continue;308 }309 310 const QString picTime = pics.at (0).trimmed();311 QString dtTime = dt.toString ("yyyyMMdd");312 313 if (picTime.startsWith (dtTime))314 {315 // picfile = pics[4];316 strTempList.append (pics[4]);317 // isNull = false;318 }319 }320 }321 322 dataFile.close();323 }324 325 return strTempList;326 }327 328 QStringList FileOpeartion::PathCombine (const QString strPath, QStringList strListTemp)329 {330 QStringList strReturn;331 332 foreach (const QString &str, strListTemp)333 {334 if (!str.isEmpty())335 {336 strReturn << strPath.trimmed() + str.trimmed();337 }338 }339 340 return strReturn;341 }342 343 344 QPixmap FileOpeartion::GetPicture (QString strPath, int mWidth, int mHeight)345 {346 QPixmap pictureimg;347 //"D:dataFolder/2015/03/15/AIA094/20150315_001402_1024_0094.jpg"348 349 if (pictureimg.load (strPath))350 {351 pictureimg = pictureimg.scaled (mWidth, mHeight, Qt::KeepAspectRatio);352 }353 354 return pictureimg;355 }356 357 FileOpeartion::~FileOpeartion (void)358 {359 }
View Code
1 #pragma once 2  3 #include 
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include "DataSource.h"11 12 class FileOpeartion13 {14 public:15 16 FileOpeartion (void);17 18 static bool GetTheTextContent (const QString strPath, QStringList &strContent);19 20 static QString GetTheTextHtml (const QString strPath);21 22 static QStringList GetThePicList (const QString strPath, QDateTime dt);23 24 static QStringList PathCombine (const QString strPath, QStringList strListTemp);25 26 static QPixmap GetPicture (QString strPath, int mWidth, int mHeight);27 28 // lyy : 2016/9/20 10:31:01 说明:先定义一个签名,没有实现,邹说要统一更改现原有的配置文件29 static QVector
GetTheSimulationRecord();30 31 ~FileOpeartion (void);32 33 34 35 };
View Code
void DailyPaper::outPrintDoc(){    QString html;    html = FileOpeartion::GetTheTextHtml ("C:/html.txt");    QFile outFile ("save.doc");    outFile.open (QIODevice::WriteOnly/* | QIODevice::Append*/);    QTextStream ts (&outFile);    ts << html << endl;    outFile.close();    //打开文件    QDesktopServices::openUrl (QUrl::fromLocalFile (QFileInfo ("save.doc").absoluteFilePath()));    //  QMessageBox::information (this, "test", "请在根目录下查看");}

设计自己的网页样式就可以了

转载于:https://www.cnblogs.com/ants-double/p/5902360.html

你可能感兴趣的文章
css选择器
查看>>
ASP.NET上传下载文件
查看>>
Galaxy Nexus 全屏显示-隐藏Navigation Bar
查看>>
Spring中使用Velocity模板
查看>>
上周热点回顾(8.18-8.24)
查看>>
Feature toggle
查看>>
day02
查看>>
gvim 配置Pydiction
查看>>
Linux安装指定mysql版本
查看>>
分布式锁的三种实现方式
查看>>
poj 2109 pow函数也能这么用?p的开n次方
查看>>
Oracle database link
查看>>
python调用shell小技巧
查看>>
TL431的几种常用用法
查看>>
js 经典闭包题目详解
查看>>
在项目中移除CocoaPods
查看>>
【洛谷】CYJian的水题大赛【第二弹】解题报告
查看>>
POJ 1703 Find them, Catch them【种类/带权并查集+判断两元素是否在同一集合/不同集合/无法确定+类似食物链】...
查看>>
L1-5. A除以B【一种输出格式错了,务必看清楚输入输出】
查看>>
Git一分钟系列--快速安装git客户端
查看>>