Converting PERL to Matlab

8 visualizaciones (últimos 30 días)
John Cochran
John Cochran el 1 de Sept. de 2016
Editada: Walter Roberson el 1 de Sept. de 2016
Hello,
I am currently developing a Matlab script to automate Microsoft Word files. I found a site that took a portion of a PERL script that says how to do this and converted it to Matlab syntax. However, I need more functions from the PERL script than the portion that is provided. Instead of pasting the whole script here, I am providing the links.
What I am currently missing is the ability to indent specific lines of my choosing. While it would be a miracle if someone could go through and convert the entire PERL script to Matlab syntax, I would be thrilled with just getting the portions related to indenting. At the moment, if I want to indent something I have to add a bunch of spaces at the beginning of the sentence, and guess/trial&error where to add a bunch more spaces in the middle of the sentence once the sentence starts to text wrap to the left margin again.
An example of the current issue I'm having:
[current]
xxxxxx
xxxxxxxxxx
xxxxx
[desired]
xxxxxx
xxxxxxx
xxxxxxx
xxxx
xxxxxxxx
xxxxx
Thank you, whoever decides to help me with this!
John
I apologize for the way my code pasted; in preview it looks like quit a mess :/
Current Code:
function SlideWriter(Headers, Titles, Bodies, ordering)
% Headers, Titles, and Bodies are arrays of strings, each string being a sentence that has its own assigned
% Font size, Font, (and hopefully indention soon) from ordering
% ordering will have values between 1 and 3
% 1: normal text font 2: Title text font 3: Header Text font
% simply put, the ordering value corresponds to font size
% length of ordering array should equal the sum of Headers, Titles, and
% Bodies
word = actxserver('Word.Application');
word.Visible = 1;
document = word.Documents.Add;
selection = word.Selection;
%Font Styles Placement
%Header
%Body Title
% Body Normal
%Footer
%Font Styles for copy-pasting
%Header
H = document.Styles.Item('Header');
H.Font.Name = 'Times New Roman';
H.Font.Size = 16;
H.Font.Bold = 1;
%Footer
F = document.Styles.Item('Footer');
F.Font.Name = 'Times New Roman';
F.Font.Size = 10;
F.Font.Bold = 0;
%Body Title
B = document.Styles.Item('Title');
B.Font.Name = 'Times New Roman';
B.Font.Size = 14;
B.Font.Bold = 1;
%Body Normal
N = document.Styles.Item('Normal');
N.Font.Name = 'Times New Roman';
N.Font.Size = 12;
N.Font.Bold = 0;
hcount = 1;
tcount = 1;
ncount = 1;
for k = 1:length(ordering)
if ordering(k) == 3
currenttext = Headers{hcount};
selection.TypeText(currenttext);
selection.Style = 'Header';
if k == 1
selection.TypeParagraph;
else
selection.TypeParagraph;
selection.TypeParagraph;
end
hcount = hcount + 1;
end
if ordering(k) == 2
currenttext = Titles{tcount};
selection.TypeText(currenttext);
selection.Style = 'Title';
selection.TypeParagraph;
selection.TypeParagraph;
tcount = tcount + 1;
end
if ordering(k) == 1
currenttext = Bodies{ncount};
selection.TypeText(currenttext);
selection.Style = 'Normal';
selection.TypeParagraph;
ncount = ncount + 1;
end
end
end

Respuestas (1)

Steven Lord
Steven Lord el 1 de Sept. de 2016
Rather than converting from Perl to MATLAB, consider calling the Perl script from within MATLAB using the perl function.
  4 comentarios
Steven Lord
Steven Lord el 1 de Sept. de 2016
The perl function does not accept individual lines of Perl code. It accepts the name of a Perl script to be executed. So if your script was in a file Word.pl you would use:
perl('Word.pl')
If it needs input arguments, specify them as additional inputs to the perl function.
perl('Word.pl', 'theNameOfMyDocument.doc')
John Cochran
John Cochran el 1 de Sept. de 2016
Editada: John Cochran el 1 de Sept. de 2016
The issue is that this PERL script doesn't perform a particular action, so much as it is a collection of available commands/functions that can be used for Word Automation. Also, I do not have the PERL file; I just have the PERL syntax listed on the website.

Iniciar sesión para comentar.

Categorías

Más información sobre Entering Commands en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by