-
Notifications
You must be signed in to change notification settings - Fork 117
ProSnippets Reports
uma2526 edited this page Jul 27, 2020
·
13 revisions
Language: C#
Subject: Reports
Contributor: ArcGIS Pro SDK Team <[email protected]>
Organization: esri, http://www.esri.com
Date: 7/9/2020
ArcGIS Pro: 2.6
Visual Studio: 2017, 2019
.NET Target Framework: 4.8
var projectReports = Project.Current.GetItems<ReportProjectItem>();
foreach (var reportItem in projectReports)
{
//Do Something with the report
}
ReportProjectItem reportProjItem = Project.Current.GetItems<ReportProjectItem>().FirstOrDefault(item => item.Name.Equals(reportName));
return reportProjItem?.GetReport();
//Note: Call within QueuedTask.Run()
//The fields in the datasource used for the report
//This uses a US Cities dataset
var listFields = new List<CIMReportField> {
//Grouping should be the first field
new CIMReportField{Name = "STATE_NAME", FieldOrder = 0, Group = true, SortInfo = FieldSortInfo.Desc}, //Group cities using STATES
new CIMReportField{Name = "CITY_NAME", FieldOrder = 1},
new CIMReportField{Name = "POP1990", FieldOrder = 2, },
};
//Definition query to use for the data source
var defQuery = "STATE_NAME LIKE 'C%'";
//Define the Datasource
//pass true to use the selection set
var reportDataSource = new ReportDataSource(featureLayer, defQuery, false, listFields);
//The CIMPage defintion - page size, units, etc
var cimReportPage = new CIMPage
{
Height = 11,
StretchElements = false,
Width = 6.5,
ShowRulers = true,
ShowGuides = true,
Margin = new CIMMargin { Bottom = 1, Left = 1, Right = 1, Top = 1 },
Units = LinearUnit.Inches
};
//Report template
var reportTemplates = await ReportTemplateManager.GetTemplatesAsync();
var reportTemplate = reportTemplates.Where(r => r.Name == "Attribute List with Grouping").First();
//Report Styling
var reportStyles = await ReportStylingManager.GetStylingsAsync();
var reportStyle = reportStyles.Where(s => s == "Cool Tones").First();
//Field Statistics
var fieldStatisticsList = new List<ReportFieldStatistic> {
new ReportFieldStatistic{ Field = "POP1990", Statistic = FieldStatisticsFlag.Sum}
//Note: NoStatistics option for FieldStatisticsFlag is not supported.
};
var report = ReportFactory.Instance.CreateReport("USAReport", reportDataSource, cimReportPage, fieldStatisticsList, reportTemplate, reportStyle);
//Note: Call within QueuedTask.Run()
//Define Export Options
var exportOptions = new ReportExportOptions
{
ExportPageOption = ExportPageOptions.ExportAllPages,
TotalPageNumberOverride = 0
};
//Create PDF format with appropriate settings
PDFFormat pdfFormat = new PDFFormat();
pdfFormat.Resolution = 300;
pdfFormat.OutputFileName = path;
report.ExportToPDF($"{report.Name}", pdfFormat, exportOptions, useSelection);
//Note: Call within QueuedTask.Run()
Item reportToImport = ItemFactory.Instance.Create(reportFile);
Project.Current.AddItem(reportToImport as IProjectItem);
//Note: Call within QueuedTask.Run()
//Reference a reportitem in a project by name
ReportProjectItem reportItem = Project.Current.GetItems<ReportProjectItem>().FirstOrDefault(item => item.Name.Equals(reportName));
//Check for report item
if (reportItem == null)
return Task.FromResult<bool>(false);
//Delete the report from the project
return Task.FromResult<bool>(Project.Current.RemoveItem(reportItem));
//Note: Call within QueuedTask.Run()
ReportProjectItem reportProjItem = Project.Current.GetItems<ReportProjectItem>().FirstOrDefault(item => item.Name.Equals(reportName));
reportProjItem.GetReport().SetName("RenamedReport");
//Note: Call within QueuedTask.Run()
//Remove Groups
// The fields in the datasource used for the report
var listFields = new List<string> {
"STATE_NAME"
};
report.RemoveGroups(listFields);
//Add Group
report.AddGroup("STATE_NAME", true, true, "");
//Modify the Definition Query
var defQuery = "STATE_NAME LIKE 'C%'";
report.SetDefinitionQuery(defQuery);
//Note: Call within QueuedTask.Run()
var cimReportPage = new CIMPage
{
Height = 12,
StretchElements = false,
Width = 6.5,
ShowRulers = true,
ShowGuides = true,
Margin = new CIMMargin { Bottom = 1, Left = 1, Right = 1, Top = 1 },
Units = LinearUnit.Inches
};
report.SetPage(cimReportPage);
//Change only the report's page height
report.SetPageHeight(12);
//Report Template Styles:
//Attribute List
//Attribute List with Grouping
//Basic Summary
//Basic Summary with Grouping
//Page Per Feature
var reportTemplates = await ReportTemplateManager.GetTemplatesAsync();
var reportTemplate = reportTemplates.Where(r => r.Name == reportTemplateName).First();
//Report Styling:
//Black and White
//Cool Tones
//Warm Tones
var reportStyles = await ReportStylingManager.GetStylingsAsync();
var reportStyle = reportStyles.Where(s => s == reportStyleName).First();
Home | API Reference | Requirements | Download | Samples
-
Gets all the reports in the current project
-
Get a specific report
-
Open a Report project item in a new view
-
Activate an already open report view
-
Reference the active report view
-
Refresh the report view
-
Zoom to whole page
-
Zoom to specific location on Report view
-
Zoom to page width