實在是不想再用水晶報表了。
經新同事國林推薦,接觸了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; }