Changing the outputted font of a wordApp code
Hi, I’ve begun writing code to open a microsoft word template, generate some outputted times and numbers, and fill the document with this info. Currently the defualt output is Aptos. How can this be changed?
My code:
% Define the file path of the existing Word document
docName = ‘test_template1.docx’; % Your document filename
docPath = ‘C:UsersmichaOneDriveDesktopTicketstest_template1.docx’;
% Check if the file exists
if exist(docPath, ‘file’)
% Create a Word application
wordApp = actxserver(‘Word.Application’);
% Check if Word application is activated
if ~isempty(wordApp)
try
% Open the existing document
wordDoc = wordApp.Documents.Open(docPath);
% FILL 1 – ID NUMBER
rng(0,’twister’);
idNum = randi([740 9850],1,1);
idNum2 =(‘idNum’);
% DATA FILL 2 – AREA
area = (‘28213’);
% DATA FILL 3 1st date
currentDate = upper(datestr(now, ‘ddd dd mmm ‘));
% Variable Set time (currently 6:30 PM)
setTime = (’06:30′);
% Add text to the document
wordApp.Selection.EndKey(6); % Go to the end of the document
wordApp.Selection.TypeParagraph; % Insert a new paragraph
wordApp.Selection.TypeText([idNum2, area, currentDate , setTime]);
% Save the document
wordDoc.Save;
% Close the document
wordDoc.Close;
% Quit Word application
wordApp.Quit;
disp(‘Document updated successfully.’);
catch exception
disp(‘An error occurred:’);
disp(exception.message);
% Close Word application
wordApp.Quit;
end
else
disp(‘Word application could not be activated.’);
end
else
disp(‘The specified Word document does not exist.’);
end
ThanksHi, I’ve begun writing code to open a microsoft word template, generate some outputted times and numbers, and fill the document with this info. Currently the defualt output is Aptos. How can this be changed?
My code:
% Define the file path of the existing Word document
docName = ‘test_template1.docx’; % Your document filename
docPath = ‘C:UsersmichaOneDriveDesktopTicketstest_template1.docx’;
% Check if the file exists
if exist(docPath, ‘file’)
% Create a Word application
wordApp = actxserver(‘Word.Application’);
% Check if Word application is activated
if ~isempty(wordApp)
try
% Open the existing document
wordDoc = wordApp.Documents.Open(docPath);
% FILL 1 – ID NUMBER
rng(0,’twister’);
idNum = randi([740 9850],1,1);
idNum2 =(‘idNum’);
% DATA FILL 2 – AREA
area = (‘28213’);
% DATA FILL 3 1st date
currentDate = upper(datestr(now, ‘ddd dd mmm ‘));
% Variable Set time (currently 6:30 PM)
setTime = (’06:30′);
% Add text to the document
wordApp.Selection.EndKey(6); % Go to the end of the document
wordApp.Selection.TypeParagraph; % Insert a new paragraph
wordApp.Selection.TypeText([idNum2, area, currentDate , setTime]);
% Save the document
wordDoc.Save;
% Close the document
wordDoc.Close;
% Quit Word application
wordApp.Quit;
disp(‘Document updated successfully.’);
catch exception
disp(‘An error occurred:’);
disp(exception.message);
% Close Word application
wordApp.Quit;
end
else
disp(‘Word application could not be activated.’);
end
else
disp(‘The specified Word document does not exist.’);
end
Thanks Hi, I’ve begun writing code to open a microsoft word template, generate some outputted times and numbers, and fill the document with this info. Currently the defualt output is Aptos. How can this be changed?
My code:
% Define the file path of the existing Word document
docName = ‘test_template1.docx’; % Your document filename
docPath = ‘C:UsersmichaOneDriveDesktopTicketstest_template1.docx’;
% Check if the file exists
if exist(docPath, ‘file’)
% Create a Word application
wordApp = actxserver(‘Word.Application’);
% Check if Word application is activated
if ~isempty(wordApp)
try
% Open the existing document
wordDoc = wordApp.Documents.Open(docPath);
% FILL 1 – ID NUMBER
rng(0,’twister’);
idNum = randi([740 9850],1,1);
idNum2 =(‘idNum’);
% DATA FILL 2 – AREA
area = (‘28213’);
% DATA FILL 3 1st date
currentDate = upper(datestr(now, ‘ddd dd mmm ‘));
% Variable Set time (currently 6:30 PM)
setTime = (’06:30′);
% Add text to the document
wordApp.Selection.EndKey(6); % Go to the end of the document
wordApp.Selection.TypeParagraph; % Insert a new paragraph
wordApp.Selection.TypeText([idNum2, area, currentDate , setTime]);
% Save the document
wordDoc.Save;
% Close the document
wordDoc.Close;
% Quit Word application
wordApp.Quit;
disp(‘Document updated successfully.’);
catch exception
disp(‘An error occurred:’);
disp(exception.message);
% Close Word application
wordApp.Quit;
end
else
disp(‘Word application could not be activated.’);
end
else
disp(‘The specified Word document does not exist.’);
end
Thanks file, file handling MATLAB Answers — New Questions