實(shí)在是不想再用水晶報(bào)表了。
經(jīng)新同事國林推薦,接觸了FashReport,感覺不錯(cuò)。
通過下面的分享,最終使用起來了。非常感謝作者的分享。
https://blog.csdn.net/u013934107/article/details/110474617
記錄一下主要的調(diào)用代碼:
private void Print()
{
// create report instance
Report report = new Report();
// load the existing report
string rptFile = "A6.frx";
if (!string.IsNullOrEmpty(cbxTemplate.Text))
{
rptFile = cbxTemplate.Text;
}
report.Load(rptFile);
List<LabelDataModel> labels = new List<LabelDataModel>();
//業(yè)務(wù)數(shù)據(jù)
// register the business object
report.RegisterData(labels, "Labels");
if (cbDesign.Checked)
{
// design the report,打開設(shè)計(jì)器
report.Design(true);
}
else
{
if (chbPrintPreview.Checked)
{
// run the report
report.Show();
}
else
{
//直接打印
report.Prepare();
report.PrintSettings.Printer = cbxPrinter.Text;
report.PrintSettings.Copies = 1;
report.PrintSettings.ShowDialog = false;
report.Print();
}
}
// free resources used by report
report.Dispose();
}
/// <summary>
/// 加載打印模板
/// </summary>
private void LoadPrintTemplate()
{
cbxTemplate.Items.Clear();
var temps = System.IO.Directory.GetFiles(Application.StartupPath, "*.frx", System.IO.SearchOption.TopDirectoryOnly);
foreach (var fileName in temps)
{
var file = new System.IO.FileInfo(fileName);
cbxTemplate.Items.Add(file.Name);
}
if (cbxTemplate.Items.Count > 0)
{
cbxTemplate.SelectedIndex = 0;
}
}
//加載打印機(jī)
private void LoadPrinters()
{
cbxPrinter.Items.Clear();
foreach (object item in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
{
cbxPrinter.Items.Add(item.ToString());
}
cbxPrinter.SelectedIndex = 0;
}
浙公網(wǎng)安備 33010602011771號(hào)