In this section, you will learn how to export a Diagram Table in CSV format.
To export a Diagram Table in the CSV format using the Magic Report plugin
- On the main menu, click Options>Environment. The Environment Options dialog opens.
- In the Report Wizard option group, click Add to add a new row in the Configure template mappings table.
- In the Template mappings dialog, add .csv as the file extension and .txt as the Template type.
- Click OK.
- Create a blank text file and copy the sample code below in the text file.
#macro(formatValue $s) #set($value = $s) #if($value.indexOf('"') >= 0 || \$value.indexOf(',') >= 0) #set($value = '"' + $s + '"') #else #foreach ($c in $value.toCharArray()) #if($c.getType($c)==15) #set($value = '"' + $s + '"') #break #end #end #end #end #import("table", "com.nomagic.reportwizard.tools.DiagramTableTool") #foreach($d in $table.filterDiagramTables($Diagram)) #set($colIds = $table.getColumnIds($d))$d.getName() #foreach($te in $table.getColumnNames($d, $colIds))#formatValue($te)$value,#end #foreach($re in $table.getRows($d)) #foreach($id in $colIds)#formatValue($table.getStringCellValue($d, $re, $id))$value,#end #end $table.clearTablesCache() #end
- Save this text file with a CSV file extension.
- Add the CSV template to the Report Wizard dialog and generate a CSV report.