实在是不想再用水晶报表了。

经新同事国林推荐,接触了FashReport,感觉不错。

通过下面的分享,最终使用起来了。非常感谢作者的分享。

https://blog.csdn.net/u013934107/article/details/110474617

 

记录一下主要的调用代码:

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>();
//业务数据
// register the business object report.RegisterData(labels, "Labels"); if (cbDesign.Checked) { // design the report,打开设计器 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; } } //加载打印机 private void LoadPrinters() { cbxPrinter.Items.Clear(); foreach (object item in System.Drawing.Printing.PrinterSettings.InstalledPrinters) { cbxPrinter.Items.Add(item.ToString()); } cbxPrinter.SelectedIndex = 0; }

  

 

posted on 2022-05-26 17:56  Louis.Lu.Sz  阅读(174)  评论(0编辑  收藏  举报