MATLAB report generator table font family

조회 수: 15 (최근 30일)
Emmanouil
Emmanouil 2019년 3월 17일
댓글: Charles Arentzen 2020년 1월 18일
Hi, I am using MATLAB R2018b and I want to create a Table in MATLAB report generator and change the font style of its data.
I tried the following code but it does not work. Any ideas?
% import package
import mlreportgen.dom.*
% create the document object
doc_obj = Document('MATLAB_test_report','pdf');
% table
tableObj = Table ( {'a','b';'5','P'} ) ;
tableObj.Width = '30pt';
tableObj.Border = 'none';
tableObj.TableEntriesStyle = {Height('20pt'),FontFamily('Calibri')};
% append
append ( doc_obj , tableObj ) ;
% close document
close(doc_obj);
% display
rptview(doc_obj);

채택된 답변

Mary Abbott
Mary Abbott 2019년 3월 18일
Hello,
The code you are using should change the font family of the table entries to Calibri. However, there is a bug in R2018b and previous releases that causes the font family of table entries to be ignored. This bug is fixed in R2019a.
As a workaround for releases prior to R2019a, you can create Paragraph objects for the table entries and set the FontFamilyName property of the objects to 'Calibri'. An example of this is shown below:
% import package
import mlreportgen.dom.*
% create the document object
doc_obj = Document('MATLAB_test_report','pdf');
% Create Paragraph objects for table data
tableData = {'a','b';'5','P'};
for k = 1:numel(tableData)
p = Paragraph(tableData{k});
p.FontFamilyName = 'Calibri';
tableData{k} = p;
end
% table
tableObj = Table ( tableData ) ;
tableObj.Width = '30pt';
tableObj.Border = 'none';
tableObj.TableEntriesStyle = {Height('20pt')};
% append
append ( doc_obj , tableObj ) ;
% close document
close(doc_obj);
% display
rptview(doc_obj);
  댓글 수: 1
Charles Arentzen
Charles Arentzen 2020년 1월 18일
Hey Mary,
Thank you very much for this answer, it was enormously helpful (using 2017b). However, I did run into another issue after following your approach. The font is corrected (and love the fact I can colorize individual table entries!), but for whatever reason the table columns autofit such that the longest entry in the column gets split into 2 lines. I unfortunately cannot show you the report as it is on another network, but hopefully that describes the issue.
Things I have tried that did not work:
  1. added ResizeToFitContents(true) as part of table style following table creation (did nothing)
  2. added whitespace after table entry (if sufficiently long, will force all actual text onto first line but will not eliminate blank second line)
Since the columns in my tables would be much better off being flexibly sized, I was hoping I would be able to read the active column widths following the first iteration of the table, and then tack on a small amount of width for each column.
Any help would be greatly appreciated.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by