필터 지우기
필터 지우기

report gnenrator mise en foirme de texte dans un tableau

조회 수: 1 (최근 30일)
Daniel MONTERRAIN
Daniel MONTERRAIN 2023년 7월 28일
편집: Kausthub 2023년 9월 1일
Bonjour,
J'utilise report generator pour mettre des tableaux de cellules contenant des textes (djà formaté) dans un rapport word. (tableaux de cellules produit dans une autre application matlab).
mon problème est que une fois le texte dans le tableau word le formatage fait dans matlab est perdu. En particulier les retour à la ligne obtenu en insérant des char(10) dans matlab sont supprimés dans le tableau word.
par example le texte ci dessous dans matlab (lers "points virgule return " sont volontaires
;
;
;
;
;
[Local operator has to open the valve (MR00131)];
[Local operator has to open the valve (MR00133)];
devient dans word
; ; ; ; ; [Local operator has to open the valve (MR00131)]; [Local operator has to open the valve (MR00133)];
on voit que word a supprimé tous les " return" ( et word ne va à la ligne que si le mot suivant ne tient pas dans la case du tableau)
or j'ai besoin de retrouver dans word la mise en forme que j'avais dans matlab. je pense que le caractère char(10) utilisé pour "aller à la ligne " dans matlab devrait être remplacé par un autre dans word (mais lequel?)
Merci pour votre aide.

답변 (2개)

Daniel MONTERRAIN
Daniel MONTERRAIN 2023년 7월 31일
bonjour
Pour la querstion ci avant , l'exemple "Create a Table from a Cell Array" du lien
fournit ce que je veux en colone 3 "characters" du tableau sauf que je ne veux ni 'puce' (les points noirs), ni tabulation.
Dans cet exemple le contenu de la troisième colone du tableau est mis sous forme d'un tableau de cellule, une ligne du tableau de cellule correspond à chaque ligne dans la "case" du tableau word. (je peux faire cela, même si c'est pas simple)
malheureusement il y a des puces et une tabulation et je ne sais pas comment les supprimer
j'ai essayé en apopliquant un style, cela supprime bien la tabulation et l'interligne, mais ca ne supprime pas les puces...
help please.

Kausthub
Kausthub 2023년 9월 1일
편집: Kausthub 2023년 9월 1일
Hi Daniel Monterrain,
I understand that you want to retain the line breaks in your text when exporting tables from MATLAB to a word document using MATLAB Report Generator.
A solution for this would be to define the text as a Paragraph and its text using the sprintf() function and “\n. Then utilize the WhiteSpace = ‘preserve’ property of paragraph to retain the line breaks when exporting it to a word document.
Here is a sample code snippet demonstrating the same:
import mlreportgen.dom.*;
doctype = 'docx';
d = Document('test', doctype);
% creating a heading
append(d, 'Table 2');
table = Table(2);
% configuring the style
table.Border = "solid";
table.BorderWidth = "1px";
table.ColSep = "solid";
table.ColSepWidth = "1";
table.RowSep = "solid";
table.RowSepWidth = "1";
% Creating a paragragh using sprintf
% Using the property of WhiteSpace = 'preserve' to display the line breaks
para = Paragraph();
append(para, Text(sprintf('first line\nsecond line\nthird line\nfourth line')));
para.WhiteSpace = 'preserve';
% Creating first row
row1 = TableRow;
append(row1, TableEntry(para));
append(row1, TableEntry('World'));
append(table, row1);
% Creating second row
row2 = TableRow;
append(row2, TableEntry('Hello2'));
append(row2, TableEntry('World2'));
append(table, row2);
append(d, table);
close(d);
rptview(d.OutputPath, doctype);
Here is a similar MATLAB answer which addresses your problem:
Here are few references that would be helpful:
Hope it helps!

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!