📄 dztp.cpp
字号:
StringGrid->Cells[4][1] = OKRightDlg->ADOTable->Fields->Fields[0]->AsString;
StringGrid->Cells[4][2] = OKRightDlg->ADOTable->Fields->Fields[1]->AsString;
StringGrid->Cells[4][3] = OKRightDlg->ADOTable->Fields->Fields[2]->AsString;
StringGrid->Cells[4][4] = OKRightDlg->ADOTable->Fields->Fields[3]->AsString;
StringGrid->Cells[4][5] = OKRightDlg->ADOTable->Fields->Fields[4]->AsString;
StringGrid->Cells[4][6] = OKRightDlg->ADOTable->Fields->Fields[5]->AsString;
StringGrid->Cells[4][7] = OKRightDlg->ADOTable->Fields->Fields[6]->AsString;
StringGrid->Cells[4][8] = OKRightDlg->ADOTable->Fields->Fields[7]->AsString;
StringGrid->Cells[4][9] = OKRightDlg->ADOTable->Fields->Fields[8]->AsString;
StringGrid->Cells[4][10] = OKRightDlg->ADOTable->Fields->Fields[9]->AsString;
StringGrid->Cells[4][11] = OKRightDlg->ADOTable->Fields->Fields[10]->AsString;
StringGrid->Cells[4][12] = OKRightDlg->ADOTable->Fields->Fields[11]->AsString;
StringGrid->Cells[4][13] = OKRightDlg->ADOTable->Fields->Fields[12]->AsString;
StringGrid->Cells[4][14] = OKRightDlg->ADOTable->Fields->Fields[13]->AsString;
StringGrid->Cells[4][15] = OKRightDlg->ADOTable->Fields->Fields[14]->AsString;
StringGrid->Cells[4][16] = OKRightDlg->ADOTable->Fields->Fields[15]->AsString;
StringGrid->Cells[4][17] = OKRightDlg->ADOTable->Fields->Fields[16]->AsString;
StringGrid->Cells[4][18] = OKRightDlg->ADOTable->Fields->Fields[17]->AsString;
StringGrid->Cells[4][19] = OKRightDlg->ADOTable->Fields->Fields[18]->AsString;
StringGrid->Cells[4][20] = OKRightDlg->ADOTable->Fields->Fields[19]->AsString;
StringGrid->Cells[4][21] = OKRightDlg->ADOTable->Fields->Fields[20]->AsString;
StringGrid->Cells[4][22] = OKRightDlg->ADOTable->Fields->Fields[21]->AsString;
StringGrid->Cells[4][23] = OKRightDlg->ADOTable->Fields->Fields[22]->AsString;
StringGrid->Cells[4][24] = OKRightDlg->ADOTable->Fields->Fields[23]->AsString;
StringGrid->Cells[4][25] = OKRightDlg->ADOTable->Fields->Fields[24]->AsString;
StringGrid->Cells[4][26] = OKRightDlg->ADOTable->Fields->Fields[25]->AsString;
OKRightDlg->ADOTable->Active = false;
}
//---------------------------------------------------------------------------
void __fastcall TDZTPForm::BitBtn2Click(TObject *Sender)
{
OKBottomDlg1->ADOTable->Active = true;
OKBottomDlg1->ShowModal();
StringGrid->Cells[6][1] = OKBottomDlg1->ADOTable->Fields->Fields[0]->AsString;
StringGrid->Cells[6][2] = OKBottomDlg1->ADOTable->Fields->Fields[1]->AsString;
StringGrid->Cells[6][3] = OKBottomDlg1->ADOTable->Fields->Fields[2]->AsString;
StringGrid->Cells[6][4] = OKBottomDlg1->ADOTable->Fields->Fields[3]->AsString;
StringGrid->Cells[6][5] = OKBottomDlg1->ADOTable->Fields->Fields[4]->AsString;
StringGrid->Cells[6][6] = OKBottomDlg1->ADOTable->Fields->Fields[5]->AsString;
StringGrid->Cells[6][7] = OKBottomDlg1->ADOTable->Fields->Fields[6]->AsString;
StringGrid->Cells[6][8] = OKBottomDlg1->ADOTable->Fields->Fields[7]->AsString;
StringGrid->Cells[6][9] = OKBottomDlg1->ADOTable->Fields->Fields[8]->AsString;
StringGrid->Cells[6][10] = OKBottomDlg1->ADOTable->Fields->Fields[9]->AsString;
StringGrid->Cells[6][11] = OKBottomDlg1->ADOTable->Fields->Fields[10]->AsString;
StringGrid->Cells[6][12] = OKBottomDlg1->ADOTable->Fields->Fields[11]->AsString;
StringGrid->Cells[6][13] = OKBottomDlg1->ADOTable->Fields->Fields[12]->AsString;
StringGrid->Cells[6][14] = OKBottomDlg1->ADOTable->Fields->Fields[13]->AsString;
StringGrid->Cells[6][15] = OKBottomDlg1->ADOTable->Fields->Fields[14]->AsString;
StringGrid->Cells[6][16] = OKBottomDlg1->ADOTable->Fields->Fields[15]->AsString;
StringGrid->Cells[6][17] = OKBottomDlg1->ADOTable->Fields->Fields[16]->AsString;
StringGrid->Cells[6][18] = OKBottomDlg1->ADOTable->Fields->Fields[17]->AsString;
StringGrid->Cells[6][19] = OKBottomDlg1->ADOTable->Fields->Fields[18]->AsString;
StringGrid->Cells[6][20] = OKBottomDlg1->ADOTable->Fields->Fields[19]->AsString;
StringGrid->Cells[6][21] = OKBottomDlg1->ADOTable->Fields->Fields[20]->AsString;
StringGrid->Cells[6][22] = OKBottomDlg1->ADOTable->Fields->Fields[21]->AsString;
StringGrid->Cells[6][23] = OKBottomDlg1->ADOTable->Fields->Fields[22]->AsString;
StringGrid->Cells[6][24] = OKBottomDlg1->ADOTable->Fields->Fields[23]->AsString;
StringGrid->Cells[6][25] = OKBottomDlg1->ADOTable->Fields->Fields[24]->AsString;
StringGrid->Cells[6][26] = OKBottomDlg1->ADOTable->Fields->Fields[25]->AsString;
OKBottomDlg1->ADOTable->Active = false;
}
//---------------------------------------------------------------------------
void __fastcall TDZTPForm::PreViewBitBtnClick(TObject *Sender)
{
Variant Ex, Wb, Sheet, ERange, EBorders;
//取报表文件CardSend.xls的完整目录名
AnsiString ExcelFileName = GetCurrentDir() + "\\Report.xls";
if(!FileExists(ExcelFileName))
{
Application->MessageBox("报表模板文件不存在,无法打开!",
"错误",MB_ICONSTOP|MB_OK);
return;
}
//建立Excel的Ole对象Ex
try
{
Ex = Variant::CreateObject("Excel.Application");
}
catch(...)
{
Application->MessageBox("无法启动Excel","错误",MB_ICONSTOP|MB_OK);
return;
}
//设置Excel为不可见
Ex.OlePropertySet("Visible",false);
//打开指定的Excel报表文件。报表文件中最好设定只有一个Sheet。
Ex.OlePropertyGet("WorkBooks").OleProcedure("Open",ExcelFileName.c_str());
Wb = Ex.OlePropertyGet("ActiveWorkBook");
Sheet = Wb.OlePropertyGet("ActiveSheet");//获得当前默认的Sheet
//读数据库中附加信息
ADOTable->TableName = "OtherInfo";
ADOTable->Active = true;
//填写附加信息
Sheet.OlePropertyGet("Cells", 3, 2).OlePropertySet("Value", ADOTable->FieldByName("检定日期")->AsString);
Sheet.OlePropertyGet("Cells", 3, 4).OlePropertySet("Value", ADOTable->FieldByName("检定温度")->AsString + "℃");
Sheet.OlePropertyGet("Cells", 3, 6).OlePropertySet("Value", ADOTable->FieldByName("温度波动")->AsString + "℃");
Sheet.OlePropertyGet("Cells", 3, 8).OlePropertySet("Value", ADOTable->FieldByName("相对湿度")->AsString + "%");
Sheet.OlePropertyGet("Cells", 3, 10).OlePropertySet("Value", ADOTable->FieldByName("样品号")->AsString);
Sheet.OlePropertyGet("Cells", 4, 2).OlePropertySet("Value", ADOTable->FieldByName("委托单位")->AsString);
Sheet.OlePropertyGet("Cells", 4, 8).OlePropertySet("Value", ADOTable->FieldByName("砝码等级")->AsString);
Sheet.OlePropertyGet("Cells", 4, 10).OlePropertySet("Value", ADOTable->FieldByName("器号")->AsString);
Sheet.OlePropertyGet("Cells", 5, 2).OlePropertySet("Value", ADOTable->FieldByName("生产单位")->AsString);
Sheet.OlePropertyGet("Cells", 5, 8).OlePropertySet("Value", ADOTable->FieldByName("砝码个数")->AsString);
Sheet.OlePropertyGet("Cells", 5, 10).OlePropertySet("Value", ADOTable->FieldByName("检定员")->AsString);
Sheet.OlePropertyGet("Cells", 6, 2).OlePropertySet("Value", ADOTable->FieldByName("g组材料")->AsString);
Sheet.OlePropertyGet("Cells", 6, 4).OlePropertySet("Value", ADOTable->FieldByName("Mg组材料")->AsString);
Sheet.OlePropertyGet("Cells", 6, 6).OlePropertySet("Value", ADOTable->FieldByName("检定依据")->AsString);
Sheet.OlePropertyGet("Cells", 6, 10).OlePropertySet("Value", ADOTable->FieldByName("核验员")->AsString);
Sheet.OlePropertyGet("Cells", 7, 2).OlePropertySet("Value", ADOTable->FieldByName("标准器编号")->AsString);
Sheet.OlePropertyGet("Cells", 7, 5).OlePropertySet("Value", ADOTable->FieldByName("检定温度")->AsString + "℃");
Sheet.OlePropertyGet("Cells", 7, 8).OlePropertySet("Value", ADOTable->FieldByName("结论")->AsString);
Sheet.OlePropertyGet("Cells", 7, 10).OlePropertySet("Value", ADOTable->FieldByName("批准人")->AsString);
ADOTable->Active = false;
//表格中写入数据
for (int i=1; i<27; i++) //行
{
for (int j=1; j<7; j++) //列
{
switch (j)
{
case 4:
Sheet.OlePropertyGet("Cells", i+9, j+2).OlePropertySet("Value", StringGrid->Cells[j][i]);
break;
case 5:
Sheet.OlePropertyGet("Cells", i+9, j+3).OlePropertySet("Value", StringGrid->Cells[j][i]);
break;
case 6:
Sheet.OlePropertyGet("Cells", i+9, j+4).OlePropertySet("Value", StringGrid->Cells[j][i]);
break;
default:
Sheet.OlePropertyGet("Cells", i+9, j+1).OlePropertySet("Value", StringGrid->Cells[j][i]);
break;
}
}
}
Wb.OlePropertySet("Saved", true); //保存表格
Ex.OlePropertySet("Visible", true);
Wb.OleProcedure("PrintPreview");
Wb.OleProcedure("Close");//关闭表格
Ex.OleFunction("Quit");//退出Excel
}
//---------------------------------------------------------------------------
void __fastcall TDZTPForm::PrintBitBtnClick(TObject *Sender)
{
Variant Ex, Wb, Sheet, ERange, EBorders;
//取报表文件CardSend.xls的完整目录名
AnsiString ExcelFileName = GetCurrentDir() + "\\Report.xls";
if(!FileExists(ExcelFileName))
{
Application->MessageBox("报表模板文件不存在,无法打开!",
"错误",MB_ICONSTOP|MB_OK);
return;
}
//建立Excel的Ole对象Ex
try
{
Ex = Variant::CreateObject("Excel.Application");
}
catch(...)
{
Application->MessageBox("无法启动Excel","错误",MB_ICONSTOP|MB_OK);
return;
}
//设置Excel为不可见
Ex.OlePropertySet("Visible",false);
//打开指定的Excel报表文件。报表文件中最好设定只有一个Sheet。
Ex.OlePropertyGet("WorkBooks").OleProcedure("Open",ExcelFileName.c_str());
Wb = Ex.OlePropertyGet("ActiveWorkBook");
Sheet = Wb.OlePropertyGet("ActiveSheet");//获得当前默认的Sheet
//读数据库中附加信息
ADOTable->TableName = "OtherInfo";
ADOTable->Active = true;
//填写附加信息
Sheet.OlePropertyGet("Cells", 3, 2).OlePropertySet("Value", ADOTable->FieldByName("检定日期")->AsString);
Sheet.OlePropertyGet("Cells", 3, 4).OlePropertySet("Value", ADOTable->FieldByName("检定温度")->AsString + "℃");
Sheet.OlePropertyGet("Cells", 3, 6).OlePropertySet("Value", ADOTable->FieldByName("温度波动")->AsString + "℃");
Sheet.OlePropertyGet("Cells", 3, 8).OlePropertySet("Value", ADOTable->FieldByName("相对湿度")->AsString + "%");
Sheet.OlePropertyGet("Cells", 3, 10).OlePropertySet("Value", ADOTable->FieldByName("样品号")->AsString);
Sheet.OlePropertyGet("Cells", 4, 2).OlePropertySet("Value", ADOTable->FieldByName("委托单位")->AsString);
Sheet.OlePropertyGet("Cells", 4, 8).OlePropertySet("Value", ADOTable->FieldByName("砝码等级")->AsString);
Sheet.OlePropertyGet("Cells", 4, 10).OlePropertySet("Value", ADOTable->FieldByName("器号")->AsString);
Sheet.OlePropertyGet("Cells", 5, 2).OlePropertySet("Value", ADOTable->FieldByName("生产单位")->AsString);
Sheet.OlePropertyGet("Cells", 5, 8).OlePropertySet("Value", ADOTable->FieldByName("砝码个数")->AsString);
Sheet.OlePropertyGet("Cells", 5, 10).OlePropertySet("Value", ADOTable->FieldByName("检定员")->AsString);
Sheet.OlePropertyGet("Cells", 6, 2).OlePropertySet("Value", ADOTable->FieldByName("g组材料")->AsString);
Sheet.OlePropertyGet("Cells", 6, 4).OlePropertySet("Value", ADOTable->FieldByName("Mg组材料")->AsString);
Sheet.OlePropertyGet("Cells", 6, 6).OlePropertySet("Value", ADOTable->FieldByName("检定依据")->AsString);
Sheet.OlePropertyGet("Cells", 6, 10).OlePropertySet("Value", ADOTable->FieldByName("核验员")->AsString);
Sheet.OlePropertyGet("Cells", 7, 2).OlePropertySet("Value", ADOTable->FieldByName("标准器编号")->AsString);
Sheet.OlePropertyGet("Cells", 7, 5).OlePropertySet("Value", ADOTable->FieldByName("检定温度")->AsString + "℃");
Sheet.OlePropertyGet("Cells", 7, 8).OlePropertySet("Value", ADOTable->FieldByName("结论")->AsString);
Sheet.OlePropertyGet("Cells", 7, 10).OlePropertySet("Value", ADOTable->FieldByName("批准人")->AsString);
ADOTable->Active = false;
//表格中写入数据
for (int i=1; i<27; i++) //行
{
for (int j=1; j<7; j++) //列
{
switch (j)
{
case 4:
Sheet.OlePropertyGet("Cells", i+9, j+2).OlePropertySet("Value", StringGrid->Cells[j][i]);
break;
case 5:
Sheet.OlePropertyGet("Cells", i+9, j+3).OlePropertySet("Value", StringGrid->Cells[j][i]);
break;
case 6:
Sheet.OlePropertyGet("Cells", i+9, j+4).OlePropertySet("Value", StringGrid->Cells[j][i]);
break;
default:
Sheet.OlePropertyGet("Cells", i+9, j+1).OlePropertySet("Value", StringGrid->Cells[j][i]);
break;
}
}
}
Wb.OlePropertySet("Saved", true); //保存表格
Ex.OlePropertySet("Visible", true);
Wb.OleProcedure("Print");
Wb.OleProcedure("Close");//关闭表格
Ex.OleFunction("Quit");//退出Excel
}
//---------------------------------------------------------------------------
void __fastcall TDZTPForm::FormShow(TObject *Sender)
{
//if (Monitor->Width != 1024)
// ScaleBy(Monitor->Width, 1024);
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -