急!中国式报表的问题。棘手.... (166分)

  • 主题发起人 主题发起人 terra
  • 开始时间 开始时间
T

terra

Unregistered / Unconfirmed
GUEST, unregistred user!
我想用Execel(word?)做好的报表(无数据,中国式,如下)
要求:
1报表模板如下
2通过程程序对表中数据区进行编辑(把SQLserver 中相关table的记录导入)
3完成后预览,打印.
|-----------------|------------|------------|----------|
|_________________|__name______|___gender___|___age____|
| |art |_class1_|____*_______|_____*______|____*_____|
| X |____|_class2_|____*_______|_____*______|____*_____|
| |math|_class3_|____*_______|_____*______|____*_____|
|___|____|_class4_|____*_______|_____*______|____*_____|
| | A | B |_B1_|____*_______|_____*______|____*_____|
| Y |____|___|_B2_|____*_______|_____*______|____*_____|
|___|_C__|___D____|____*_______|_____*______|____*_____|
(*代表需从数据库导入的记录)
注视大富翁多日,似乎还没有中国式报表的最终解决方案,小试了一下RBuilder,fastReport
..好象都是基于band的,一条band占满report一行,作美式报表到是强大,但中式报表至少
我还不知道怎么做,还请大家多多指点.Creport倒是能画出空的中式报表就是不知道怎么将
数据库中的数据导到相应的cell中(至今还不知道王大侠99年就研制成功的那个控件做些什
么,怎么用,要是有谁肯share 一个demo感激不尽).
无奈只有借助Excel了,求助:
1.用那几个控件
2.如何用
3.请有经验的高手能share 一下程序
4.如果你有更好的方法可避开Excel最好,请赐教.
 
RBuilder可以做到,我做过的。
按第一列分组。
 
用EXCEL也"挺"好的呀[:D]
 
server下。ole也可
搜索一下,
delphi的帮助太少
 
请ccweifen能否说得详细些,发一个小样如何?您的帮助对我非常重要.
mailto:terraguo@263.net
 
用一个控件不就解决问题了,请看该控件的使用说明,想要的话mail me:chenyu0745@163.com
===================
TExcel component 3.2
====================
TExcel is a component to produce output tables directly into
MS Excel, including formatting, commands, macro calls, etc.
Demo project is attached to show how easy to drive it.
The demo project creates the component explicitly so it can be
tried without installing the component.

Files:
EXCELS.PAS Component source
EXCELS.INC Include messages
EXCELS.DCR Component resource for Delphi 1.0
EXCELS.D32 Component resource for Delphi 3.0 (rename to DCR)
EXCELDEM.DPR Demo project
EXCELDEM.RES Demo project resource
EXCELTOP.PAS Demo dialog
EXCELTOP.DFM Demo dialog format
EXCEL.XLS Demo Excel macro collection
EXCEL.TXT This file
TExcel is available at the following sites:
(Thanks to Stefan Hoffmeister the sophisticated
version named TAdvExcel is also available there.)
Delphi Super Page
http://sunsite.icm.edu.pl/delphi/
http://www.cdrom.com/pub/delphi_www/
http://ring.aist.go.jp/archives/pc/delphi/
http://ftp.powerup.com.au/webmirror/delphi/
Torry's Delphi Pages
http://carbohyd.siobc.ras.ru/torry/
http://www.deltacom.ru/torry/
http://torry.rimini.com/
http://www.torry.pp.ru/
http://www.snc.ru/~torry/

===================
About Compatibility
===================
Version 3.2 has left some methods and properties which became
unnecessary due to Batch feature (see next section).
Apart from this it is fully compatible to version 3.1 and 3.0.
===================
About Batch Feature
===================
When huge amount of data must be transferred to Excel you can use
the batch methods and properties. These are the following:
procedure BatchStart(FirstRow, FirstCol: Integer);
procedure BatchSend;
procedure BatchCancel;
property Lines : TStrings;
property BatchOn : Boolean;
property BatchMin : Integer;
property BatchMax : Integer;
property FirstRow : Integer;
property LastCol : Integer;
Each BatchStart must be followed by BatchSend or BatchCancel.
After BatchStart the results of PutStr, PutExt, PutInt and
PutDay methods are collected in Lines (TStringList).
When the Lines.Count reaches BatchMax the first BatchMin
lines are transferred to Excel and deleted from Lines,
besides this FirstRow is increased.
It is recommended to process output by rows.
BatchSend transfers all cells collected in Lines and calls
BatchCancel which clears Lines.
WARNING! In Excel the whole bounding rectangle (batch area)
of the referred cells will be replaced.
All not referred cells in the rectangle will be cleared.
FirstRow always shows which Excel row is the first in Lines.
LastCols shows the greatest cell index in the processed lines.
BachOn shows the batch status. When BatchOn is false or you
refer a row less then
FirstRow or column less then
FirstCol
the put methods (PutStr, PutExt, PutInt and PutDay) are
directly executed.
Transfer speed can be increased if Lines are prepared.
The cells must be separated by tab (#9) in each line (see demo).
Further speed increasing can be achieved
if Excel is restored instead of minimized.
RESTRICTIONS! The Excel DDE buffer cannot be larger then
64 KB.
For Delphi 1.0 the length of lines cannot be
longer then
255 character including separators.
(See buffer checking in demo.)
===============================
About Receiving Data from Excel
===============================
Though TExcel is to produce output to Excel sometimes input is
also needed. GetCell retrieves the contents of the specified cell.
When many cells needed it is recommended to use the GetRange method.
GetRange returns the specified area of the current Excel worksheet
in the stringlist given as Lines. Each cell is separated by tab (#9).
RESTRICTIONS are the same as case of batch (see previous section)!
WARNING! When Batch is on, cells in the batch area are NOT AVAILABLE!
==================
Excel DDE commands
==================
To tell the truth I have never seendo
cumentation of Excel DDE
commands but I have found that most of Excel 4.0 macro instructions
work as DDE commands. So all you have todo
make a macro using the
desired instruction in Excel 4.0 format and use it as DDE command.
(With Excel 5.0 and 7.0 you can record macro in 4.0 format.)
The demo project shows some samples in the "Command" combo box.

=================================================================
Instead ofdo
cumentation here are some words about the interface.
=================================================================
procedure Connect;
To connect Excel.
procedure Disconnect;
To disconnect Excel.
procedure Wait;
To wait for Excel to be ready.
Needed when more thousands commands are executed in a loop.
procedure ProcessMessages;
To permit Windows to process (Excel) messages.
function Request(const Item: string): string;
To request for a DDE item.
Use "SysItems" to get the available items.
procedure Exec(const Cmd : string);
To execute Excel commands. See section "Excel DDE Commands".
procedure Run(const Mn: string);
To execute a macro of the open macro file.
procedure Select(Row, Col: Integer);
To select a cell of the active Excel sheet.
procedure PutStr(Row, Col: Integer;
const s: string);
To replace the cell with string.
procedure PutExt(Row, Col: Integer;
e: Extended);
virtual;
To replace the cell with real number.
procedure PutInt(Row, Col: Integer;
i: Longint);
virtual;
To replace the cell with integer.
procedure PutDay(Row, Col: Integer;
d: TDateTime);
virtual;
To replace the cell with date value.
procedure BatchStart;
To start processing. See section "About Batch...".
procedure BatchCancel;
To cancel batch processing. See section "About Batch...".
procedure BatchSend;
To finish batch processing. See section "About Batch...".
procedure GetRange(R: TRect;
Lines: TStrings);
To receive many data from Excel. See section "About Receive...".
function GetCell(Row, Col: Integer): string;
To get the cell contents. See section "About Receive...".
procedure OpenMacroFile(const Fn: TFileName;
Hide: Boolean);
To specify a macro file.
Needed only when macros are going to call.
procedure CloseMacroFile;
To close an opened macro file.
Only one macro file can be opened at the same time.
property DDE: TDdeCLientConv;
To handle DDE directly. (Read only)
Normally not needed.
property Connected: Boolean;
To check connection.
property Ready: Boolean;
To check Excel status. (Read only)
property Selection: string;
To get current selection. (Read only)
property Lines : TStrings;
To handle batch strings directly. See section "About Batch...".
property FirstRow : Integer;
To check batch area. (Read only) See section "About Batch...".
property LastCol : Integer;
To check or set batch area. See section "About Batch...".
property BatchOn : Boolean;
To check batch status. (Read only) See section "About Batch...".
property ExeName: TFileName;
To set Excel path. If it is not set before connection
it will be set due to Windows Registry.
property Decimals: Integer;
To specify number format for real numbers.
property BatchMin : Integer;
To calibrate batch processing. See section "About Batch...".
property BatchMax : Integer;
To calibrate batch processing. See section "About Batch...".
property OnClose: TNotifyEvent;
Event handler called when Excel is connected.
property OnOpen: TNotifyEvent;
Event handler called when Excel is disconnected.

--------------------------------------
--------------------------------------
TExcel is provided free of charge as so long as
it is not in commercial use. When it produces
income for you, please send me some portion of
your income (at least $50). Thank you.
 
好像犯了一个错误:EXCEL似乎还不能实现上述表格,只能在word中画得出,怎么办?
 
我给你发介creport的demo吧,请留下email
 
操作word中的表格好像只有等微软先行动一步了。
你说的问题还不够清楚
 
terraguo@263.net
如果您曾今作过中国式报表,我的问题就是如何去实现上述报表的生成,预览,打印。
 
利用QuickRep.OnNeedData事件完全可以实现的。
首先数据要按分组进行排序,并用变量记下当前的分组内容,当内容有变,说明当前组显示完毕,
这个时机就是调整格线的时机。至于格线的显示与否,只是作为格线的QRShape的高度加1减1的事了。
 
在word中画好表格,
wordapplication,worddocument调用word模板,
将table的值写到模板里
搞定
 
5rain6sky提出的是如何组织数据将其导入的表中。
但我关心的是如果用QuickReport等报表控件,报表左侧的复杂网格怎么作?
要知道Detailband之类band可是横贯整张报表呀。
(我原来在问题中的报表似乎还不足以体现中国式报表相对美式报表的复杂---
美式中每条记录就占报表一整行,所以我又到原文中对报表进行了一些修改,
请大家再考虑考虑)
 
可以使用 FIBOOK 使用合并单元格
 
用fastreport就可以了!
在fastreport中有很多方法来完成这个任务。其中一种就是:
不用band,用直线画出设计表格(想怎么画,就怎么画,很爽!),再将text控件放在指定的位置,
不用TfrDataSet,该用TfrUserDataSet,就可以在TfrUserDataSet的事件中给text赋值了。
OK!
 
用FASTREPORT,应该能实现的
 
以前我看过一个FastReport的Demo可以做到,但是我没有用过,目前也没有做过这种报表,不过我觉
得QuickReport也是可以做到的,因为这不是传统自动报表的格式,无论用什么控件,可能都不是很简
单可以做到的,只不过编程过程哪一个更复杂一些而已,要用好QuickReport,关键是要用好几个Band
和它们的事件,只是我现在没有精力研究这个问题!我赞成5rain6sky的方法,其实他的方法不是告诉
你如何导入Excel的数据,而是真正的告诉你怎么做,只不过好象太简单了,没有太多的帮助,但是你
顺着这个方向去研究一下,应该是可以的。

主要要在OnNeedData事件中控件左边的表头部份横格线是否需要画出来和需要画什么内容。
 
其中最主要的条件是你必须手工给QrLabel填充数据,而不能用数据感知报表控件,你需要明确的知道当前打印到了第几行了,关于如何手工给QRLabel填弃数据,如何知道当前打印行数,如何利用OnNeedData事件,在我的主页http://aizb.myetang.com上有详细的Demo你仔细分析一下吧!
 
后退
顶部