将stringgrid数据输出为报表形式,并打印预览以及打印,用什么方式比较简便,最好有例子

mozhou 2003-03-07 10:42:31
数据来源不是记录集,而是一个字符串分解而得,怎么实现打印好,谢谢大家
conjee@163.net
...全文
94 27 打赏 收藏 转发到动态 举报
写回复
用AI写文章
27 条回复
切换为时间正序
请发表友善的回复…
发表回复
rgcsm 2003-06-11
  • 打赏
  • 举报
回复
可以用FASTREPORT的frUserDataset组件实现stringgrid的输出。
flowercity 2003-05-17
  • 打赏
  • 举报
回复
没这么复杂的,下面的程序就解决这个问题。而且同时显示图形报表
程序如下:
//stringgrid的报表打印问题,整个页面就放四个band:pagehead,crossdata,masterdata,
//masterfooter
//在crossdata和masterdata交叉处放一个memo,里面放[cell]
//在masterfooter里面放置一个picture,align属性设置为center,去掉伸展属性


void addTopicInFR(TfrReport *frReport1)
{
//处理表头

TfrMemoView* v = new TfrMemoView(); //定义memo
TfrBandView* b = new TfrBandView(); //定义band
TfrPage* Page ;
Page = frReport1->Pages->Pages[0];

b->SetBounds(0, 20, 0, 20); // 设置band的属性
b->BandType = btReportTitle ;
Page->Objects->Add(b);

v->SetBounds(20, 20, 200, 20); //设置memo的属性
v->BandAlign = baWidth;
v->FillColor = clTeal;
v->Prop["Alignment"] = frtaCenter;
v->Prop["Font.Style"] = 2 ;
v->Prop["Font.Color"] = clWhite ;
v->Memo->Add("数据分析结果报表打印");
Page->Objects->Add(v);

}
//--------------------------------------------------------------------------

void __fastcall TDataMiningForm::Button1Click(TObject *Sender)
{

//输出chart图片到文件中
Chart1->SaveToBitmapFile("e:\\tang.bmp");

//处理表头
addTopicInFR(frReport1);

//打印输出
ColDataset->RangeEnd = reCount;
ColDataset->RangeEndCount = StringGrid1->ColCount;
RowDataset->RangeEnd = reCount;
RowDataset->RangeEndCount = StringGrid1->RowCount;

frReport1->Title = "数据分析结果报表" ;
frReport1->ShowReport() ;
}
//---------------------------------------------------------------------------

void __fastcall TDataMiningForm::frReport1GetValue(
const AnsiString ParName, Variant &ParValue)
{
if (AnsiCompareText(ParName, "Cell") == 0)
{
ParValue = StringGrid1->Cells[ColDataset->RecNo][RowDataset->RecNo];
}
}
//---------------------------------------------------------------------------

void __fastcall TDataMiningForm::frReport1BeforePrint(TStringList *Memo,
TfrView *View)
{
int index;
TfrPictureView* pic ;

if (Memo->Find("[Pic]",index)) //显示chart里面的图片
{
pic = (TfrPictureView*)View;
pic->Picture->LoadFromFile("E:\\tang.bmp");
}
View->dx = w ;
}
//---------------------------------------------------------------------------

void __fastcall TDataMiningForm::frReport1PrintColumn(int ColNo,
int &Width)
{
Width = 720/(StringGrid1->ColCount + 1) ; //打印报表栏数大于12就改变宽度
if (Width < 48)
Width = 60;
w = Width ;
}
//---------------------------------------------------------------------------



nekpy 2003-03-20
  • 打赏
  • 举报
回复
我试了一下上面的程序,为什么我的stringband能够显示出来,但是看不到里面的字呢?
dong12 2003-03-15
  • 打赏
  • 举报
回复
watercelery(空心菜) 把程序也发给我一份,qiu_dong_ying@163.com,谢谢!
csdnhe 2003-03-13
  • 打赏
  • 举报
回复
watercelery(空心菜) 把程序也发给我一份,soniche@163.com,谢谢!
mozhou 2003-03-12
  • 打赏
  • 举报
回复
watercelery(空心菜):
你的方法很实用,但是如果遇到记录比较多的时候,分页有点问题
watercelery 2003-03-11
  • 打赏
  • 举报
回复
我的那段程序,可以把StringGrid的内容全部显示,而且边框线全都有,全都是对齐的,连StringGrid宽度过大,不可以打印都给你判断了。你试试吧。。
wt_sanlian 2003-03-11
  • 打赏
  • 举报
回复
QRLabel2 -> Caption = QRStrinsBand1 -> Items[QRStringsBand1 -> Index]

QRLabel2 -> Caption = QRStringsBand1 -> Item;
mozhou 2003-03-11
  • 打赏
  • 举报
回复
QRStringsBand1没有ItemIndex这个属性!!!
wt_sanlian 2003-03-11
  • 打赏
  • 举报
回复
不要在循环中赋值
在QRStringsBand的OnBeforePrint中对QRLabel2进行赋值
QRLabel2 -> Caption = QRStrinsBand1 -> Items[QRStringsBand1 -> ItemIndex]
mozhou 2003-03-11
  • 打赏
  • 举报
回复
谢谢大家, watercelery(空心菜) 最好把程序发给我,乱码不怎么好整,conjee@163.net
wt_sanlian 2003-03-10
  • 打赏
  • 举报
回复
在QRReport1 上放一个QRStringsBand,再在QRStrinsBand 上放一外QRLabel,其宽度等于QRStringsBand的宽度.

在主程序中,

AnsiString OneLine;

for( int i =0 ; i < StringGrid1 -> RowCount; i ++ )
{
OneLine = "";
for( int j = 0; j < StringGrid1 -> ColCount; j ++)
{
OneLine = OneLine + " " StringGrid1 -> Cells[j][i];
}
QRReport1 -> Items -> Add(OneLine);
}
QRReport1 -> Preview();

OneLine变量将StringGrid1 中的一行数据累加成一个字符串,你可以根据自已的需要来排列格式!
mozhou 2003-03-10
  • 打赏
  • 举报
回复
fielders=new TQRLabel(Title);
fielders->Parent=Title;
Title是什么意思?
mozhou 2003-03-10
  • 打赏
  • 举报
回复
老大,由于QRLabel只有一个,所以其值为最后一个赋值
mozhou 2003-03-10
  • 打赏
  • 举报
回复
打印预览,发现所有的记录都是StringGrid的最后一条记录,奇怪!!
mozhou 2003-03-10
  • 打赏
  • 举报
回复
这个办法当然知道,问题是这样一来又不好对齐了
wt_sanlian 2003-03-10
  • 打赏
  • 举报
回复
再加一个QRBand控件,设为title类型的,再在上边加上列头不就行了 !!!
mozhou 2003-03-10
  • 打赏
  • 举报
回复
如果我要在列标题下面加下划线呢
wt_sanlian 2003-03-10
  • 打赏
  • 举报
回复
也可在QRStringsBand的OnBeforePrint中对QRLabel2进行赋值
QRLabel2 -> Caption = QRStrinsBand1 -> Items[QRStringsBand1 -> ItemIndex]
mozhou 2003-03-10
  • 打赏
  • 举报
回复
这种方式较为简便
加载更多回复(7)

13,874

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧