支持将图头和成果表,输出到excel文件。(参照老版本,实际是按照txt文本保存)
This commit is contained in:
parent
9610ec0ecf
commit
e73337e29b
|
|
@ -889,7 +889,8 @@ void FormHead::slotContextMenu(QPoint pos)
|
|||
else {
|
||||
strMenu= "保存为成果表模板";
|
||||
}
|
||||
menu.addAction(QIcon(::GetImagePath() + "icon/Save.png"), strMenu, this, &FormHead::slotSaveJsonModel);
|
||||
menu.addAction(QIcon(::GetImagePath() + "icon/SaveAsTemplate.png"), strMenu, this, &FormHead::slotSaveJsonModel);
|
||||
menu.addAction(QIcon(::GetImagePath() + "icon/Save.png"), "输出到excel文件", this, &FormHead::slotOutSheet);
|
||||
menu.addSeparator();
|
||||
|
||||
menu.addAction(QIcon(::GetImagePath() + "icon/MergeCell.png"), "合并单元格", this, &FormHead::slotMerge);
|
||||
|
|
@ -914,6 +915,12 @@ void FormHead::slotSaveJsonModel()
|
|||
m_parent->slotSaveJsonModel();
|
||||
}
|
||||
|
||||
//输出到excel文件
|
||||
void FormHead::slotOutSheet()
|
||||
{
|
||||
m_parent->slotOutSheet();
|
||||
}
|
||||
|
||||
//合并
|
||||
void FormHead::slotMerge()
|
||||
{
|
||||
|
|
@ -1508,3 +1515,42 @@ void FormHead::setRowHeight_Property(int row, double height)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FormHead::makeXls(QFile *file)
|
||||
{
|
||||
int columnCount = ui->tableWidget->columnCount();//总列数
|
||||
int rowCount = ui->tableWidget->rowCount();//总行数
|
||||
|
||||
for(int row=0; row<rowCount; row++)
|
||||
{
|
||||
for(int col=0; col<columnCount; col++)
|
||||
{
|
||||
FormTableItem* formTableItemTmp = nullptr;
|
||||
auto myWidget = ui->tableWidget->cellWidget(row, col);
|
||||
if(myWidget)
|
||||
{
|
||||
formTableItemTmp = (FormTableItem*)myWidget;//获得widget
|
||||
if(!formTableItemTmp)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
//
|
||||
QString text = formTableItemTmp->m_strShowTxt;
|
||||
text.replace("\r\n","");
|
||||
text.replace("\n","");
|
||||
file->write(text.toStdString().c_str());
|
||||
if(col != columnCount-1)
|
||||
{
|
||||
file->write("\t");
|
||||
}
|
||||
// fprintf(fp,"%s",text.toStdString().c_str());
|
||||
// if(col != columnCount-1) fprintf(fp,"\t");
|
||||
}
|
||||
else{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
file->write("\n");
|
||||
//fprintf(fp,"\n");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <QWidget>
|
||||
#include <QTableWidgetItem>
|
||||
#include <QFile>
|
||||
#include "formmultiheads.h"
|
||||
#include "formtableitem.h"
|
||||
|
||||
|
|
@ -54,6 +55,8 @@ public:
|
|||
void resizeEvent(QResizeEvent *event);
|
||||
QJsonObject makeJson();
|
||||
|
||||
void makeXls(QFile *file);
|
||||
|
||||
//获取表格的实际大小
|
||||
void getTableSize_Biggest(int &iWidth, int &iHight);
|
||||
//设置列宽
|
||||
|
|
@ -78,6 +81,7 @@ public slots:
|
|||
void slotContextMenu(QPoint pos);
|
||||
|
||||
void slotSaveJsonModel();//保存图头模板
|
||||
void slotOutSheet();//输出到excel文件
|
||||
//
|
||||
void slotMerge();//合并
|
||||
void slotSplit();//拆分
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@
|
|||
#include "qtcommonclass.h"
|
||||
#include "CallManage.h"
|
||||
#include "geometryutils.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
extern QString g_prjname;
|
||||
|
||||
extern int g_iRows;
|
||||
|
|
@ -19,6 +21,8 @@ extern int g_iRowsHight;
|
|||
extern int g_iFixedWidth;
|
||||
extern int g_iFixedHeight;
|
||||
extern double g_dPixelPerCm;//每厘米像素数
|
||||
//主窗口,为了方便获取tab当前页
|
||||
extern MainWindow *g_mainWindow;
|
||||
|
||||
FormMultiHeads::FormMultiHeads(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
|
|
@ -145,6 +149,57 @@ void FormMultiHeads::slotSaveJsonModel()
|
|||
}
|
||||
}
|
||||
|
||||
//输出到excel文件
|
||||
void FormMultiHeads::slotOutSheet()
|
||||
{
|
||||
QString strTmpName = "";
|
||||
|
||||
int curIndex = g_mainWindow->m_centerWidgets->currentIndex();
|
||||
strTmpName = g_mainWindow->m_centerWidgets->tabText(curIndex);
|
||||
//去掉后缀.json
|
||||
int ind=strTmpName.lastIndexOf(".");
|
||||
if(ind>=0) strTmpName=strTmpName.left(ind);
|
||||
|
||||
//
|
||||
QString pdfName = GetOutDataPath();
|
||||
if(strTmpName != "")
|
||||
{
|
||||
pdfName=pdfName + "/" + strTmpName +".xls";
|
||||
}
|
||||
|
||||
//
|
||||
QString defaultTempleteFile =QFileDialog::getSaveFileName( NULL,"输出为xls文件",pdfName,"xls文件(*.xls)");
|
||||
if(defaultTempleteFile=="") {
|
||||
return;
|
||||
}
|
||||
|
||||
// 写入文件
|
||||
QFile file(defaultTempleteFile);
|
||||
if(file.open(QIODevice::WriteOnly)){
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::information(nullptr, "保存文件失败", defaultTempleteFile);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
int rowCount = ui->tableWidget->rowCount();//总行数
|
||||
for(int i=0; i<rowCount; i++)
|
||||
{
|
||||
if( ui->tableWidget->cellWidget(i, 0) != nullptr )
|
||||
{
|
||||
auto myWidget = ui->tableWidget->cellWidget(i, 0);
|
||||
FormHead *widgetHead = qobject_cast<FormHead*>(myWidget);
|
||||
if(widgetHead)
|
||||
{
|
||||
widgetHead->makeXls(&file);
|
||||
}
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
|
||||
}
|
||||
|
||||
void FormMultiHeads::loadStyle(const QString &qssFile)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -42,6 +42,9 @@ public slots:
|
|||
void slotSaveJsonModel();
|
||||
QJsonObject makeJsonModel();
|
||||
|
||||
//输出到excel文件
|
||||
void slotOutSheet();
|
||||
|
||||
public:
|
||||
void loadStyle(const QString &qssFile);
|
||||
void AddHead();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user