日期:2014-05-19  浏览次数:20871 次

C#中做报表除了用水晶报表还能用什么做 ?
感觉水晶报表打开很慢   ,   第一次打开一张报表要10秒左右   。


------解决方案--------------------
报表不是很复杂的话可以用PrintDocument,需要写代码
我自己正好在写一个模板打印的代码
public class CustomPrinter
{
public float LineBetween = 1;
private string TempletName;
private DataTable Table;
private Font DefualtFont = new Font( "楷体_GB2312 ", 16);
private string txt;
public PrintDocument printDocument;
private float yPosition;
private int currentPage = 0;
public CustomPrinter()
{
}
public CustomPrinter(string templteName, DataTable table)
{
TempletName = templteName;
Table = table;
printDocument = new PrintDocument();
printDocument.PrintController = new StandardPrintController();
printDocument.PrintPage += new PrintPageEventHandler(Print);
printDocument.BeginPrint += new PrintEventHandler(BeginPrint);
}

private void BeginPrint(object sender, PrintEventArgs e)
{
currentPage = 0;
txt = ExplainText();
}

private void Print(object sender, PrintPageEventArgs e)
{
yPosition = e.MarginBounds.Top;
if (currentPage == 0)
{
Font titleFont = new Font( "黑体 ", DefualtFont.Size + 2);
float xTitle = e.MarginBounds.Left + (e.MarginBounds.Width - e.Graphics.MeasureString(TempletName, titleFont).Width) / 2;
e.Graphics.DrawString(TempletName, titleFont, Brushes.Black, xTitle, yPosition);
yPosition += e.Graphics.MeasureString(TempletName, titleFont).Height * LineBetween;
}
PrintJustLine(e);
}

private string ExplainText()
{
string newtxt = " ";
txt = File.ReadAllText(Path.Combine(Application.StartupPath, string.Format(@ "{0}\{1}.TML ", "Templet ", TempletName)), Encoding.Default);
string[] txtlist = txt.Split(new char[] { '{ ', '} ' });
for (int i = 0; i < txtlist.Length; i++)
{
txtlist[i] = GetValue(txtlist[i]);
newtxt += txtlist[i];
}
return newtxt;
}

private void SetFormat(string field)
{
try
{
string[] format = field.Split(new char[] { '= ' });
if (format[0].ToUpper().Equals( "FontName ".ToUpper())) DefualtFont = new Font(format[1], DefualtFont.Size);
if (format[0].ToUpper().Equals( "FontSize ".ToUpper())) DefualtFont = new Font(DefualtFont.Name, float.Parse(format[1]));
if (format[0].ToUpper().Equals( "Between ".ToUpper())) LineBetween = float.Parse(format[1]);
}
catch { }
}

private string GetValue(string field)
{
if (field.IndexOf( "= ") > 0)
{
SetFormat(field);
return " ";
}

string value = field;
if (Table.Columns[field] != null)
{
value = Table.Rows[0][field].ToString();
}
else
{
switch (field)
{
case "ChequeId ":