Unable to edit table in my Report
4 views (last 30 days)
Show older comments
Hello,
I am new to coding/Matlabs and have run into an issue with my script that I am working on. My intention with this script is to take a .csv and make it pretty by generating a more presentable "Report." This report will break the table into 2 different tables, one for calibration and one for a final verification of the output.
Where I am having an issue is with the styling of the table. Nothing I seem to do changes the fontsize, style, padding, etc. Did I do something in my code that prevents me editing the table any styling for the report?
Here is my code:
%% Import report API classes
import mlreportgen.report.*
import mlreportgen.dom.*
%% Clear content
clear;
%% Select .csv file to pull information from
[file, path] = uigetfile('*.csv');
file_name = strcat(path, file);
csv_file = fopen(file_name);
%% Set up the Import Options and import the data
opts = delimitedTextImportOptions("NumVariables", 14);
% Specify range and delimiter
opts.DataLines = [2, Inf];
opts.Delimiter = ",";
% Specify column names and types
opts.VariableNames = ["UNIT_", "CALTIME", "CAL_ADJ", "CPM", "PEAK", "PEAKSD", "PEAKTARG", "PEAKERR", "RESID", "RESIDSD", "RESIDMAXSPEC", "DYNRANGE", "PW", "PASS_FAIL"];
opts.VariableTypes = ["categorical", "categorical", "categorical", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "categorical"];
% Specify file level properties
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
% Specify variable properties
opts = setvaropts(opts, ["UNIT_", "CALTIME", "CAL_ADJ", "PASS_FAIL"], "EmptyFieldRule", "auto");
% Make data set from .csv file
caldata = readtable(file, opts);
%% Format Table Style
caldata.Style = [caldata.Style
{NumberFormat("%1.3f"),...
Width("100%"),...
Border("solid"),...
ColSep("solid"),...
RowSep("solid")}];
caldata.TableEntriesHAlign = "center";
append(rpt, caldata);
%% Create File and type
rpt = Report('output','docx');
%% Add content to Report
% Title Page
titlepg = TitlePage;
titlepg.Title = 'Project Title';
titlepg.Author = 'Company Name';
titlepg.PubDate = date;
add (rpt, titlepg);
% Table of contents
add (rpt, TableOfContents);
% Calibration Report
calr = Chapter('Calibration Report');
add (rpt, calr);
%head(caldata, 16) %Call Calibration rows from table
ta = head(caldata, 16);
append(rpt,ta);
% Append changes to table format
%append(rpt,caldata);
% Performance Verification Report
perfr = Chapter('Performance Report');
add (rpt, perfr);
%tail(caldata, 16) %Call Performance rows from table
caldata = tail(caldata, 16);
append(rpt,caldata);
%% Clear temporary variables
clear opts
%% Close Report
close (rpt);
%% Display Data
%display(caldata);
%Show Final Report
rptview(rpt);
0 Comments
Accepted Answer
C B
on 9 Oct 2021
you need to create mlreportgen.dom.table
caldataNew = mlreportgen.dom.Table(caldata);
caldataNew =
Table with properties:
ColSpecGroups: [1×14 mlreportgen.dom.TableColSpecGroup]
NCols: 14
NRows: 33
Width: []
HAlign: []
BackgroundColor: []
Border: 'solid'
BorderColor: []
BorderWidth: '100px'
RowSep: 'single'
RowSepColor: []
RowSepWidth: []
ColSep: 'single'
ColSepColor: []
ColSepWidth: []
BorderCollapse: []
FlowDirection: []
OuterLeftMargin: []
TableEntriesStyle: {[1×1 mlreportgen.dom.HAlign]}
TableEntriesVAlign: []
TableEntriesHAlign: 'center'
TableEntriesInnerMargin: []
StyleName: 'rgMATLABTable'
Style: {[1×1 mlreportgen.dom.Border] [1×1 mlreportgen.dom.ColSep] [1×1 mlreportgen.dom.RowSep]}
CustomAttributes: []
Parent: []
Children: [1×33 mlreportgen.dom.TableRow]
Tag: 'dom.Table:20111'
Id: '20111'
This all property you can set or style them after setting.
Please find below part of your code updated.
It it fullfill your requirement please click on "Accept this Answer"
% Make data set from .csv file
caldata = readtable(file, opts);
caldataNew = mlreportgen.dom.Table(caldata);
%% Format Table Style
caldataNew.Border='solid';
caldataNew.BorderWidth='100';
caldataNew.ColSep='Single';
caldataNew.RowSep='Single';
caldataNew.TableEntriesHAlign = "center";
%% Create File and type
rpt = Report('output','docs');
append(rpt, caldataNew);
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!