谢谢,搞定了。
public class EngineeringReportType
{
public string ID { get; set; }
public string Name { get; set; }
public string Path { get; set; }
public string FileName { get; set; }
public Dictionary<string, object> ReportDataSourceDic { get; set; }
}
EngineeringReportType aTreeSelectItem =null;
if (aTreeSelectItem != null)
{
string aExportPath = string.Empty;//导出路径
string aNewFileName = aTreeSelectItem.Name+".xlsx";//新文件名
System.Windows.Forms.FolderBrowserDialog aFolder = new FolderBrowserDialog();
aFolder.ShowDialog();
if(!string.IsNullOrWhiteSpace(aFolder.SelectedPath))
{
aExportPath = aFolder.SelectedPath;
}
else
{
MessageBox.Show("请选择导出位置"); return;
}
string aPath = Utils.SystemSetting.RegSettings.ReportPath + aTreeSelectItem.Path + aTreeSelectItem.FileName;
GrapeCity.ActiveReports.PageReport _repPage = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(aPath));
GrapeCity.ActiveReports.Document.PageDocument _reportRuntime = new GrapeCity.ActiveReports.Document.PageDocument(_repPage);
_reportRuntime.LocateDataSource += (send, args) =>
{
object reportData = null;
if (aTreeSelectItem.ReportDataSourceDic != null)
reportData = aTreeSelectItem.ReportDataSourceDic.Where(i => i.Key.Equals(args.DataSetName)).FirstOrDefault().Value;
args.Data = reportData;
};
GrapeCity.ActiveReports.Export.Excel.Section.XlsExport xlsExport1 = new GrapeCity.ActiveReports.Export.Excel.Section.XlsExport();
xlsExport1.FileFormat = GrapeCity.ActiveReports.Export.Excel.Section.FileFormat.Xlsx;
xlsExport1.Export(_reportRuntime, aExportPath + "\\" + aNewFileName);
MessageBox.Show("导出完成");
}
|