如何使用Devexpress获取已经在C#.Net中创建的模板/报告
本文关键字:创建 报告 Net Devexpress 何使用 获取 | 更新日期: 2023-09-27 18:20:56
我在C#.Net中使用DevExpress
工具进行项目。我创建了一些模板/报告(XtraReport),并通过此链接创建了单独显示这些模板的按钮。
现在我需要获得所有模板的名称,并希望在DropDown中显示,最终用户选择并单独查看每个模板??
我可以从设计器中获得我创建的模板,并从bin>Debug>UserTemplates.repx格式文件外部存储这些模板,并使用此代码存储在下拉列表中并显示在预览中。
printBarManager1.PrintControl = printControl1;
XtraReport RptObj = XtraReport.FromFile(Application.StartupPath + @"'UserTemplates'" + CBL_QuoteTempList.EditValue + ".repx", true);
RptObj.CreateDocument();
printControl1.PrintingSystem = RptObj.PrintingSystem;
但是我需要得到我创建的模板吗?如何获取?去哪里?建议我或帮助我解决这个问题。
提前谢谢。Srihari
据我所知,您有一个包含*.repx文件的文件夹,但您不知道如何让用户选择其中一个。
您可以使用此代码加载组合
public static void loadCombo(ComboBoxEdit control)
{
string path = @"C:'FolderWithRepxFiles'";
string[] filePaths = Directory.GetFiles(path, "*.repx");
control.Properties.Items.Clear();
foreach (string item in filePaths)
control.Properties.Items.Add(System.IO.Path.GetFileNameWithoutExtension(item));
}
然后您可以使用此打印/打印预览报告
public static void PrintPreview(ComboBoxEdit control)
{
string selection = control.SelectedItem as string;
string fullPath = @"C:'FolderWithRepxFiles'" + selection + ".repx";
XtraReport rr = XtraReport.FromFile(fullPath, true);
ReportPrintTool printTool = new ReportPrintTool(rr);
printTool.ShowRibbonPreview();
//printTool.Print();
}
若要自定义保存过程,必须创建一个自定义命令处理程序。以下是您的操作方法:
XRDesignRibbonForm designForm = new XRDesignRibbonForm();
designForm.OpenReport(Your_Report_Object);
XRDesignPanel panel = designForm.ActiveDesignPanel;
designForm.ActiveDesignPanel.SetCommandVisibility(ReportCommand.SaveFileAs, DevExpress.XtraReports.UserDesigner.CommandVisibility.None);
designForm.ActiveDesignPanel.SetCommandVisibility(ReportCommand.SaveAll, CommandVisibility.None);
designForm.ActiveDesignPanel.SetCommandVisibility(ReportCommand.ShowPreviewTab, CommandVisibility.None);
designForm.ActiveDesignPanel.SetCommandVisibility(ReportCommand.ShowHTMLViewTab, CommandVisibility.None);
designForm.ActiveDesignPanel.SetCommandVisibility(ReportCommand.ShowTabbedInterface, CommandVisibility.None);
if (panel != null)
panel.AddCommandHandler(new SaveCommandHandler(panel));
designForm.ShowDialog();
您将需要此类
public class SaveCommandHandler : DevExpress.XtraReports.UserDesigner.ICommandHandler
{
XRDesignPanel panel;
string NewPathX = null;
public SaveCommandHandler(XRDesignPanel panel)
{
this.panel = panel;
}
void Save()
{
//Show a form with a textbox and ask the user to give you a name for the report
string fileName = "UserSelectedFileName";
fileName = @"C:'YourDefaultFolder" + fileName + ".repx";
panel.Report.SaveLayout(fileName);
panel.ReportState = ReportState.Saved;
}
public bool CanHandleCommand(ReportCommand command, ref bool useNextHandler)
{
useNextHandler = command != ReportCommand.SaveFile;
return command == ReportCommand.SaveFile;
}
public void HandleCommand(ReportCommand command, object[] args)
{
bool handled = false;
if (!CanHandleCommand(command, ref handled)) return;
Save();
}
}
有关此的详细信息:
https://documentation.devexpress.com/#xtrareports/CustomDocument2211http://www.devexpress.com/Support/Center/Example/Details/E4354
这是你需要的吗?