Main Content

Export Requirement and Link Information to Excel

This example shows how to use Requirements Toolbox™ to export requirement and link information programmatically. The example constructs a custom function that you can use on a requirement set and saves the information as an Excel® spreadsheet.

Inspect the Export Function

Open the attached MATLAB® program file, reqXlsExport.m, to view the function code. The function uses programmatic commands to export the information to an Excel file.

The function takes three input arguments in order:

  1. The requirement set that you want to export, specified as a character vector. The argument must include the .slreqx extension.

  2. The name of the Excel file that you want to save the requirements to, specified as a character vector. The name must include the .xls extension.

  3. The properties that you want to export, specified as a cell array of character vectors. You can also include properties of the links associated with the requirements. Specify at least one requirement property.

reqXlsExport can retrieve this built-in requirement information, which corresponds to the respective slreq.Requirement class properties:

  • Id

  • Index

  • Summary

  • Description

  • Rationale

  • Keywords

  • CreatedOn

  • Dirty

  • ModifiedOn

  • ModifiedBy

  • SID

You specify one or more of the properties in the property cell array argument.

The Description and Rationale properties normally return text that includes formatting commands. Exporting this text obscures the text in Excel. To prevent this, the reqXlsExport code uses the getDescriptionAsText and getRationaleAsText methods to return the description and rationale as plain text.

reqXlsExport can also retrieve the associated link information of the requirements. The function code uses the slreq.getIncomingLinkTypeLabel and slreq.getOutgoingLinkTypeLabel to establish the headers in the table for each link direction and identifies if the label corresponds to the requirement by using the getOutgoingTypeLabel, getIncomingTypeLabel, getSourceLabel, and getDestinationLabel methods. To retrieve the link information, you must load the links associated with the requirements before executing the function.

You export the link information by using these syntaxes:

  • '<links-in>': Exports the incoming link labels associated with the requirements and groups them by type.

  • '<links-out>': Exports the incoming link labels associated with the requirements and groups them by type.

You can also specify the link type associated with the requirement by entering a colon and the link type after links-out or links-in. For example, to populate the table with associated outgoing links of the verify type, include '<links-out:verify>' in the cell array.

You can also specify custom attributes from stereotypes and custom link types. For more information on defining custom attributes and link types, see Add Custom Attributes to Requirements and Define Custom Requirement and Link Types and Properties.

After retrieving the requirement and link information, the function consolidates the information as an array and uses the writecell function to export the array to Excel.

Export Requirements from Project

In this example, you export requirement information in a MATLAB project. Open the attached example project, CruiseRequirementsSafetyExample.

addpath(pwd)
openProject("CruiseRequirementsSafetyExample");

Next, open the requirement set that you want to export and the files that contain associated information, such as link sets, models, and tests.

sysReqSeqSet = slreq.open("crs_req.slreqx");
funcReqSet = slreq.open("crs_req_func_spec.slreqx");
sltest.testmanager.load("crs_controller_tests.mldatx");
sltest.testmanager.load("DriverSwRequest_Tests.mldatx");
open_system("crs_controller");
open_system("crs_plant");
open("crs_controllerdic.sldd");

After loading the requirement set and the supporting files, use reqXlsExport. For example, to export the system requirements together with linking details, enter this code:

outFile = 'sys_req_export.xls';
columnConfig = {'Index','Id','Type','Summary',...
    'Description','<links-out:Derive>'};
reqXlsExport(sysReqSeqSet, outFile, columnConfig)

The Excel spreadsheet is configured similarly to the Link Details pane in the Requirements Editor.

You can specify as few or as many of the properties that you want to retrieve. For example, to export the creation and modification information for the functional requirement set, crs_req_func_spec.slreqx, enter:

outFile = 'full_func_req_export.xls';
columnConfig = {'Index','Id','Type','Summary','Description','Rationale',...
    '<links-in:Implement>','<links-in:Verify>','Keywords',...
    'CreatedOn','CreatedBy','ModifiedOn','ModifiedBy','SID'};
reqXlsExport(funcReqSet, outFile, columnConfig)

Clean Up

Clear the open requirement sets and links without saving changes and close the open models and tests without saving changes.

slreq.clear;
bdclose all;

See Also

Functions

Classes

Related Topics