matlab生成word模板

matlab gui一个成绩录入系统

function varargout = grade_word(varargin)
% GRADE_WORD MATLAB code for grade_word.fig
%      GRADE_WORD, by itself, creates a new GRADE_WORD or raises the existing
%      singleton*.
%
%      H = GRADE_WORD returns the handle to a new GRADE_WORD or the handle to
%      the existing singleton*.
%
%      GRADE_WORD('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GRADE_WORD.M with the given input arguments.
%
%      GRADE_WORD('Property','Value',...) creates a new GRADE_WORD or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before grade_word_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to grade_word_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help grade_word

% Last Modified by GUIDE v2.5 04-Jun-2018 12:05:13

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @grade_word_OpeningFcn, ...
    'gui_OutputFcn',  @grade_word_OutputFcn, ...
    'gui_LayoutFcn',  [] , ...
    'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before grade_word is made visible.
function grade_word_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to grade_word (see VARARGIN)

% Choose default command line output for grade_word
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes grade_word wait for user response (see UIRESUME)
% uiwait(handles.figure1);
global original_path
original_path=pwd;
axis(handles.axes1);
b=[original_path,'\logo.png'];
imshow(b);



% --- Outputs from this function are returned to the command line.
function varargout = grade_word_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in pb_selce_excel.
function pb_selce_excel_Callback(hObject, eventdata, handles)
% hObject    handle to pb_selce_excel (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global excel_file_path
[fileName,pathName]=uigetfile({'*.xls;*.xlsx','Excel Files(*.xls,*.xlsx)';'*.*','All Files(*.*)'},'请选择Excel表');
excel_file_path=[pathName,fileName];
if excel_file_path==0
    errordlg('未选择文件','无效','replace');   %提示错误  加上replace防止弹出多个窗口
end
data=xlsread(excel_file_path,'J5:J65');
global score_num
score_num=length(data);
% --- Executes on selection change in pm_course_name.
function pm_course_name_Callback(hObject, eventdata, handles)
% hObject    handle to pm_course_name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns pm_course_name contents as cell array
%        contents{get(hObject,'Value')} returns selected item from pm_course_name



% --- Executes during object creation, after setting all properties.
function pm_course_name_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pm_course_name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in pm_time_start.
function pm_time_start_Callback(hObject, eventdata, handles)
% hObject    handle to pm_time_start (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns pm_time_start contents as cell array
%        contents{get(hObject,'Value')} returns selected item from pm_time_start


% --- Executes during object creation, after setting all properties.
function pm_time_start_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pm_time_start (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in pm_term.
function pm_term_Callback(hObject, eventdata, handles)
% hObject    handle to pm_term (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns pm_term contents as cell array
%        contents{get(hObject,'Value')} returns selected item from pm_term


% --- Executes during object creation, after setting all properties.
function pm_term_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pm_term (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in pm_class_time.
function pm_class_time_Callback(hObject, eventdata, handles)
% hObject    handle to pm_class_time (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns pm_class_time contents as cell array
%        contents{get(hObject,'Value')} returns selected item from pm_class_time


% --- Executes during object creation, after setting all properties.
function pm_class_time_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pm_class_time (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in pm_time_end.
function pm_time_end_Callback(hObject, eventdata, handles)
% hObject    handle to pm_time_end (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns pm_time_end contents as cell array
%        contents{get(hObject,'Value')} returns selected item from pm_time_end


% --- Executes during object creation, after setting all properties.
function pm_time_end_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pm_time_end (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in pm_exam_year.
function pm_exam_year_Callback(hObject, eventdata, handles)
% hObject    handle to pm_exam_year (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns pm_exam_year contents as cell array
%        contents{get(hObject,'Value')} returns selected item from pm_exam_year


% --- Executes during object creation, after setting all properties.
function pm_exam_year_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pm_exam_year (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in pm_exam_month.
function pm_exam_month_Callback(hObject, eventdata, handles)
% hObject    handle to pm_exam_month (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns pm_exam_month contents as cell array
%        contents{get(hObject,'Value')} returns selected item from pm_exam_month


% --- Executes during object creation, after setting all properties.
function pm_exam_month_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pm_exam_month (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in pm_exam_day.
function pm_exam_day_Callback(hObject, eventdata, handles)
% hObject    handle to pm_exam_day (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns pm_exam_day contents as cell array
%        contents{get(hObject,'Value')} returns selected item from pm_exam_day


% --- Executes during object creation, after setting all properties.
function pm_exam_day_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pm_exam_day (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in pm_exam_class.
function pm_exam_class_Callback(hObject, eventdata, handles)
% hObject    handle to pm_exam_class (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns pm_exam_class contents as cell array
%        contents{get(hObject,'Value')} returns selected item from pm_exam_class


% --- Executes during object creation, after setting all properties.
function pm_exam_class_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pm_exam_class (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pb_repot.
function pb_repot_Callback(hObject, eventdata, handles)
% hObject    handle to pb_repot (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% 利用MATLAB生成Word文档
% 成绩.xls放在同一目录下,程序会自动读取表格并计算
% 画图并自动生成试卷分析.doc

global original_path excel_file_path
global courseName %课程名称
global studyTime %学时
global classTime%上课时间
global examTime%考试日期
global examClass%考试班级
%课程名称----------------------------------------
index=get(handles.pm_course_name,'value');
str=get(handles.pm_course_name,'String');
courseName=char(str(index));
courseName=['课程名称:',courseName];
%学时--------------------------------------------
index=get(handles.pm_class_time,'value');
str=get(handles.pm_class_time,'String');
studyTime=char(str(index));
studyTime=['学时:',studyTime];
%上课时间----------------------------------------
index=get(handles.pm_time_start,'value');
str=get(handles.pm_time_start,'String');

timeStart=char(str(index));


index=get(handles.pm_time_end,'value');
str=get(handles.pm_time_end,'String');
timeEnd=char(str(index));




index=get(handles.pm_term,'value');
str=get(handles.pm_term,'String');
termN=char(str(index));

classTime=['上课时间:',timeStart,'至',timeEnd,'学年 第',termN,'学期'];

%考试日期------------------------------------------
index=get(handles.pm_exam_year,'value');
str=get(handles.pm_exam_year,'String');
year=char(str(index));


     index=get(handles.pm_exam_month,'value');
    str=get(handles.pm_exam_month,'String');
    month=char(str(index));

   index=get(handles.pm_exam_day,'value');
   str=get(handles.pm_exam_day,'String');
   day=char(str(index));

    examTime=['考试日期:',year,'年',month,'月',day,'日'];   

   
     index=get(handles.pm_exam_month,'value');
    str=get(handles.pm_exam_month,'String');
    month=char(str(index));

   index=get(handles.pm_exam_day,'value');
   str=get(handles.pm_exam_day,'String');
   day=char(str(index));

    examTime=['考试日期:',year,'年',month,'月',day,'日'];   


%考试班级--------------------------------------------
index=get(handles.pm_exam_class,'value');
str=get(handles.pm_exam_class,'String');
examClass=char(str(index));
examClass=['考试班级:',examClass];
%-----------------------------------------------------
filespec_user = [original_path '\试卷分析.doc'];

% 判断Word是否已经打开,若已打开,就在打开的Word中进行操作,否则就打开Word
try
    %若Word服务器已经打开,返回句柄Word
    Word = actxGetRunningServer('Word.Application');
catch
    %创建一个Microsoft Word服务器,返回句柄Word
    Word = actxserver('Word.Application');
end;

Word.Visible = 1;        %设置Word属性为可见

% 若测试文件存在,打开该测试文件,否则,新建一个文件,并保存,文件名为测试.doc
if exist(filespec_user,'file')
    Document = Word.Documents.Open(filespec_user);
    %  Document = invoke(Word.Documents,'Open',filespec_user);
else
    Document = Word.Documents.Add;
    try
        Document.SaveAs(filespec_user);
    catch
        Document.SaveAs2(filespec_user);
    end
end

Content = Document.Content;
Selection = Word.Selection;

Paragraphformat = Selection.ParagraphFormat;

% 页面设置
Document.PageSetup.TopMargin = 60;
Document.PageSetup.BottomMargin = 45;
Document.PageSetup.LeftMargin = 45;
Document.PageSetup.RightMargin = 45;

% 设定文档内容的起始位置和标题
Content.Start = 27;
PicturePath=[original_path '\su.PNG'];
h1 = Document.Shapes.AddPicture(PicturePath,0,1,145,1,200,20);%
headline = '1';
Content.Text = headline;%输入文字内容
Content.Font.Size = 10 ;%设置字号为16
Content.Font.Bold = 2 ;%字体加粗


Selection.Start = Content.end;%设定下面内容的起始位置
Selection.TypeParagraph;%回车,另起一段
Selection.TypeParagraph;
Selection.Font.Size = 12;
Selection.Font.Bold = 0;
Paragraphformat = Selection.ParagraphFormat;
Paragraphformat.Alignment = 'wdAlignParagraphLeft';
% 在光标所在位置插入一个26行6列的表格
Tables = Document.Tables.Add(Selection.Range,26,6);
DTI = Document.Tables.Item(1);          % 或DTI = Tables;
% 设置表格边框
DTI.Borders.OutsideLineStyle = 'wdLineStyleSingle';%所有表格最外面的边框
DTI.Borders.OutsideLineWidth = 'wdLineWidth100pt';%所有表格最外面的边框的宽度
DTI.Borders.InsideLineStyle = 'wdLineStyleSingle';%里面这些小边框的样式
DTI.Borders.InsideLineWidth = 'wdLineWidth100pt';%里面这些小边框的宽度
DTI.Rows.Alignment = 'wdAlignRowCenter';
% DTI.Rows.Alignment = 'wdAlignRowLeft';
DTI.Cell(20,1).Range.Paragraphs.Alignment = 'wdAlignParagraphRight';
DTI.Cell(3,1).Range.Paragraphs.Alignment = 'wdAlignParagraphLeft';
DTI.Cell(26,5).Range.Paragraphs.Alignment = 'wdAlignParagraphRight';
 DTI.Cell(18,2).VerticalAlignment = 'wdCellAlignVerticalCenter';



DTI.Rows.Item(1).Borders.Item(1).LineStyle = 'wdLineStyleNone';%这一句执行之后第一条横着的边框没了
DTI.Rows.Item(2).Borders.Item(1).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(2).Borders.Item(2).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(3).Borders.Item(1).LineStyle = 'wdLineStyleNone';%同上
DTI.Rows.Item(3).Borders.Item(2).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(4).Borders.Item(1).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(4).Borders.Item(2).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(5).Borders.Item(1).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(6).Borders.Item(1).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(6).Borders.Item(2).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(1).Borders.Item(2).LineStyle = 'wdLineStyleNone';%第一个表格框框的左边部分没了
DTI.Rows.Item(3).Borders.Item(2).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(5).Borders.Item(2).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(5).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(11).Borders.Item(4).LineStyle = 'wdLineStyleNone';%第八行最后面的那个表格右边框线没了
DTI.Rows.Item(3).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(5).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(18).Borders.Item(2).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(18).Borders.Item(3).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(19).Borders.Item(2).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(19).Borders.Item(3).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(20).Borders.Item(2).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(20).Borders.Item(3).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(21).Borders.Item(2).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(21).Borders.Item(3).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(22).Borders.Item(2).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(22).Borders.Item(3).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(23).Borders.Item(2).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(24).Borders.Item(1).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(24).Borders.Item(2).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(24).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(25).Borders.Item(1).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(25).Borders.Item(2).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(25).Borders.Item(3).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(26).Borders.Item(2).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(26).Borders.Item(3).LineStyle = 'wdLineStyleNone';

DTI.Cell(1,1).Borders.Item(4).LineStyle = 'wdLineStyleNone';%单独一个表格操作
DTI.Cell(1,4).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(1,5).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(1,6).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(2,1).Borders.Item(4).LineStyle = 'wdLineStyleNone';

DTI.Cell(2,2).Borders.Item(4).LineStyle = 'wdLineStyleNone';

DTI.Cell(2,3).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(2,4).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(2,5).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(2,6).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(3,1).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(3,2).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(3,3).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(3,6).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(4,1).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(4,2).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(4,3).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(4,6).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(5,1).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(5,2).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(5,3).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(5,6).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(6,1).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(6,2).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(6,3).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(6,6).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(11,1).Borders.Item(2).LineStyle = 'wdLineStyleNone';
DTI.Cell(11,1).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(18,1).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(18,2).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(18,3).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(18,6).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(19,1).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(19,6).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(20,1).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(20,6).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(21,1).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(21,3).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(21,6).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(22,1).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(22,6).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(23,1).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(23,6).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(24,1).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(24,6).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(25,1).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(25,2).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(25,3).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(25,4).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(25,5).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(25,6).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(26,1).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(26,2).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(26,3).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(26,4).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(26,5).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(26,6).Borders.Item(4).LineStyle = 'wdLineStyleNone';


% 设置表格列宽和行高
column_width = [115.7736,65.1434,65.7736,65.094,65.7736,...
    75.0094];
row_height = [15.4717,8.4717,15.4717,8.4717,15.4717,8.4717,15.4717,15.4717,15.4717,15.4717,10.4717,25.4717,10.4717,10.4717,10.4717,...
    10.4717,10.4717,15.4717,15.4717,150.2453,15.4717,15.4717,15.4717,15.4717,15.2453,15.2453];
for i = 1:6
    DTI.Columns.Item(i).Width = column_width(i);
end
for i = 1:26
    DTI.Rows.Item(i).Height = row_height(i);
end

for i = 7:17
    for j = 1:6
        DTI.Cell(i,j).VerticalAlignment = 'wdCellAlignVerticalCenter';
        DTI.Cell(i,j).Range.Paragraphs.Alignment = 'wdAlignParagraphCenter';
    end
end
DTI.Cell(21,1).Range.Paragraphs.Alignment = 'wdAlignParagraphCenter';
DTI.Cell(21,2).Range.Paragraphs.Alignment = 'wdAlignParagraphCenter';
DTI.Cell(21,6).Range.Paragraphs.Alignment = 'wdAlignParagraphCenter';
% 合并单元格
DTI.Cell(1, 1).Merge(DTI.Cell(1, 6));
DTI.Cell(2, 1).Merge(DTI.Cell(2, 6));
DTI.Cell(3, 1).Merge(DTI.Cell(3, 6));
DTI.Cell(4, 1).Merge(DTI.Cell(4, 6));
DTI.Cell(5, 1).Merge(DTI.Cell(5, 2));
DTI.Cell(5, 2).Merge(DTI.Cell(5, 5));
DTI.Cell(6, 1).Merge(DTI.Cell(6, 6));
DTI.Cell(7, 1).Merge(DTI.Cell(7, 2));
DTI.Cell(8, 1).Merge(DTI.Cell(8, 2));
DTI.Cell(9, 1).Merge(DTI.Cell(9, 2));
DTI.Cell(10, 1).Merge(DTI.Cell(10, 2));
DTI.Cell(11, 1).Merge(DTI.Cell(11, 6));
DTI.Cell(18, 2).Merge(DTI.Cell(18, 6));
DTI.Cell(19, 1).Merge(DTI.Cell(19, 6));
DTI.Cell(20, 1).Merge(DTI.Cell(20, 6));
DTI.Cell(21, 1).Merge(DTI.Cell(21, 6));
DTI.Cell(22, 1).Merge(DTI.Cell(22, 6));
DTI.Cell(23, 1).Merge(DTI.Cell(23, 6));
DTI.Cell(24, 1).Merge(DTI.Cell(24, 6));
DTI.Cell(26, 5).Merge(DTI.Cell(26, 6));
DTI.Cell(25, 5).Merge(DTI.Cell(25, 6));
DTI.Cell(25, 3).Merge(DTI.Cell(25, 4));
% DTI.Cell(26, 2).Merge(DTI.Cell(26, 3));

% 写入表格内容
len1=length(courseName);
while len1<34
    courseName=[courseName,' '];
    len1=len1+1;
end
rowtxt1=[courseName,studyTime];
len2=length(classTime);
while len2<30
    classTime=[classTime,' '];
    len2=len2+1;
end
rowtxt2=[classTime,examTime];
len1=length(rowtxt1);
len2=length(rowtxt2);

DTI.Cell(1,1).Range.Text=rowtxt1;
DTI.Cell(3,1).Range.Text = rowtxt2;
DTI.Cell(5,1).Range.Text = examClass;%'考试班级:';
DTI.Cell(7,1).Range.Text = '考试人数';
DTI.Cell(7,2).Range.Text = '最高分';
DTI.Cell(7,3).Range.Text = '最低分';
DTI.Cell(7,4).Range.Text = '平均分';

data=xlsread(excel_file_path,'J5:J65');
global score_num
score_max=max(data);
score_min=min(data);
score_mean=mean(data);
DTI.Cell(8,1).Range.Text = (num2str(score_num));%考试人数

DTI.Cell(8,2).Range.Text = (num2str(score_max));
DTI.Cell(8,3).Range.Text = (num2str(score_min));
DTI.Cell(8,4).Range.Text = (num2str(roundn(score_mean,-2)));
DTI.Cell(9,1).Range.Text = '90-100分';
DTI.Cell(9,2).Range.Text = '80-89分';
DTI.Cell(9,3).Range.Text = '70-79分';
DTI.Cell(9,4).Range.Text = '60-69分';
DTI.Cell(9,5).Range.Text = '59分以下';
num_90_100=length(find(  data >=90 &  data <= 100 ));
num_80_89=length(find(  data >=80 &  data <= 89 ));
num_70_79=length(find(  data >=70 &  data <= 79 ));
num_60_69=length(find(  data >=60 &  data <= 69 ));
num_59=length(find(  data >=0 &  data < 60 ));
DTI.Cell(10,1).Range.Text = [num2str(num_90_100),'人 ',num2str(roundn(num_90_100/score_num*100,-2)),'%'];
DTI.Cell(10,2).Range.Text = [num2str(num_80_89),'人 ',num2str(roundn(num_80_89/score_num*100,-2)),'%'];
DTI.Cell(10,3).Range.Text = [num2str(num_70_79),'人 ',num2str(roundn(num_70_79/score_num*100,-2)),'%'];
DTI.Cell(10,4).Range.Text = [num2str(num_60_69),'人 ',num2str(roundn(num_60_69/score_num*100,-2)),'%'];
DTI.Cell(10,5).Range.Text = [num2str(num_59),'人 ',num2str(roundn(num_59/score_num*100,-2)),'%'];

global persit1 persit2 persit3
if persit1==1
    persitStr1='学生对所学课程产生了较大兴趣 ';
else
    persitStr1='';
end
if persit2==1
    persitStr2='班级学习氛围良好 ';
else
    persitStr2='';
end
if persit3==1
    persitStr3='学生对基本知识的掌握程度大大提高 ';
else
    persitStr3='';
end
persitStr=['4  持续改进(针对上年度课程中存在的问题,本年度改进方案的落实情况和效果):',persitStr1,persitStr2,persitStr3];

%--------------------------------------------------------
global reason1 reason2 reason3 reason4 reason5

if reason1==1
    reasonStr1='教学方法与学生方法配合不好 ';
else
    reasonStr1='';
end
if reason2==1
    reasonStr2='班级学习风气欠佳 ';
else
    reasonStr2='';
end
if reason3==1
    reasonStr3='命题范围未覆盖教学全部内容 ';
else
    reasonStr3='';
end
if reason4==1
    reasonStr4='命题难度较大 ';
else
    reasonStr4='';
end
if reason5==1
    reasonStr5='考核方法不符合课程特点 ';
else
    reasonStr5='';
end
reasonStr=['2  问题及原因分析(教学方法,内容,学习风气,命题范围、难度,考核方式等):',reasonStr1,reasonStr2,reasonStr3,reasonStr4,reasonStr5];
%--------------------------------------------------------------------------------------
global improve1 improve2 improve3 improve4
if improve1==1
    improveStr1='注重基本知识、基本理论 ';
else
    improveStr1='';
end
if improve2==1
    improveStr2='及时和学生沟通教学方法 ';
else
    improveStr2='';
end
if improve3==1
    improveStr3='调动班级学习氛围 ';
else
    improveStr3='';
end
if improve4==1
    improveStr4='综合分析课程特点,合理设置试题难度 ';
else
    improveStr4='';
end
improveStr=['3  改进方案:',improveStr1,improveStr2,improveStr3,improveStr4];





DTI.Cell(12,1).Range.Text = '本学期主要知识点';
DTI.Cell(12,2).Range.Text = '90分以上(优)';
DTI.Cell(12,3).Range.Text = '80-89分(良)';
DTI.Cell(12,4).Range.Text = '70-79分(中)';
DTI.Cell(12,5).Range.Text = '60-69分(及格)';
DTI.Cell(12,6).Range.Text = '59分以下(不及格)';
DTI.Cell(18,1).Range.Text = '试卷情况分析:';%(考试成绩是否属于正态分布、从成绩分布看学生对各知识点的掌握情况,原因、对策等)';
DTI.Cell(18,1).Range.Font.Size = 14;
DTI.Cell(18,1).Range.Font.Bold = 2;
DTI.Cell(18,2).Range.Text = '(成绩分布分析;问题及原因分析;改进方案;持续改进)';


DTI.Cell(19,1).Range.Text = '1  成绩分布分析(是否属于正态分布、从成绩分布看学生对各知识点的掌握情况)';
DTI.Cell(22,1).Range.Text = reasonStr;%'2  问题及原因分析(教学方法,内容,学习风气,命题范围、难度,考核方式等)';
DTI.Cell(23,1).Range.Text = improveStr;%'3  改进方案                 ';
DTI.Cell(24,1).Range.Text = persitStr;%'4  持续改进(针对上年度课程中存在的问题,本年度改进方案的落实情况和效果)';
DTI.Cell(25,3).Range.Text = '     报告人_________';
DTI.Cell(25,4).Range.Text = '教研室主任_________';
DTI.Cell(26,5).Range.Text = '     ___年___月___日';


global txt1_1 txt1_2 txt1_3 txt1_4 txt1_5 txt1_6
global txt2_1 txt2_2 txt2_3 txt2_4 txt2_5 txt2_6
global txt3_1 txt3_2 txt3_3 txt3_4 txt3_5 txt3_6
global txt4_1 txt4_2 txt4_3 txt4_4 txt4_5 txt4_6
global txt5_1 txt5_2 txt5_3 txt5_4 txt5_5 txt5_6
if txt1_1~=0
    DTI.Cell(13,1).Range.Text =txt1_1;
    DTI.Cell(13,2).Range.Text =txt1_2;
    DTI.Cell(13,3).Range.Text =txt1_3;
    DTI.Cell(13,4).Range.Text =txt1_4;
    DTI.Cell(13,5).Range.Text =txt1_5;
    DTI.Cell(13,6).Range.Text =txt1_6;
end
if txt2_1~=0
    DTI.Cell(14,1).Range.Text =txt2_1;
    DTI.Cell(14,2).Range.Text =txt2_2;
    DTI.Cell(14,3).Range.Text =txt2_3;
    DTI.Cell(14,4).Range.Text =txt2_4;
    DTI.Cell(14,5).Range.Text =txt2_5;
    DTI.Cell(14,6).Range.Text =txt2_6;
end
if txt3_1~=0
    DTI.Cell(15,1).Range.Text =txt3_1;
    DTI.Cell(15,2).Range.Text =txt3_2;
    DTI.Cell(15,3).Range.Text =txt3_3;
    DTI.Cell(15,4).Range.Text =txt3_4;
    DTI.Cell(15,5).Range.Text =txt3_5;
    DTI.Cell(15,6).Range.Text =txt3_6;
end
if txt4_1~=0
    DTI.Cell(16,1).Range.Text =txt4_1;
    DTI.Cell(16,2).Range.Text =txt4_2;
    DTI.Cell(16,3).Range.Text =txt4_3;
    DTI.Cell(16,4).Range.Text =txt4_4;
    DTI.Cell(16,5).Range.Text =txt4_5;
    DTI.Cell(16,6).Range.Text =txt4_6;
end
DTI.Rows.Item(25).Borders.Item(3).LineStyle = 'wdLineStyleNone';



% 绘图并放置于表格单元(20,1)
zft = figure('units','normalized','position',...
    [0.25 0.53 0.4 0.18],'visible','off'); % 定义句柄
% 绘图
set(gca,'position',[0.12 0.31 0.5 0.6])%;[0.17 0.17 0.6 0.6]);
stats = (0:1:100);
h = ksdensity(data,stats)
plot(stats,h,'k','LineWidth',2);
hold on;
x = 0:1:100;
y = normpdf(x,mean(data),std(data));
xlabel('考试成绩');
ylabel('f(x)')
plot(x,y,'R','LineWidth',2);
legend('试卷概率密度函数','理论正态分布的概率密度函数','Location','NorthWest');
grid off;
hgexport(zft, '-clipboard'); % 将图片复制到剪切板
DTI.Cell(20,1).Range.Paragraphs.Item(1).Range.PasteSpecial; % 粘贴操作
Shape.Item(1).WrapFormat.Type = 3;
delete(zft); % 删除句柄
 [mu,sigma]=normfit(data);
 p1=normcdf(data,mu,sigma);
 [h1,s1]=kstest(data,[data,p1],0.05);
if h1==1
    DTI.Cell(21,1).Range.Text = '成绩分布不符合正态分布';
end
if h1==0
    DTI.Cell(21,1).Range.Text = '成绩分布符合正态分布';
end

Document.ActiveWindow.ActivePane.View.Type = 'wdPrintView';
Document.Save; % 保存文档
%Word.Quit; % 关闭文档


% --- Executes on button press in improveMethds.
function improveMethds_Callback(hObject, eventdata, handles)
% hObject    handle to improveMethds (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of improveMethds
val=get(hObject,'value');
if val==1
    improve_methods;
end

% --- Executes on button press in persistImprove.
function persistImprove_Callback(hObject, eventdata, handles)
% hObject    handle to persistImprove (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of persistImprove
val=get(hObject,'value');
if val==1
    persit_improve;
end

% --- Executes on button press in reasons.
function reasons_Callback(hObject, eventdata, handles)
% hObject    handle to reasons (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of reasons
val=get(hObject,'value');
if val==1
    qustion_and_reason;
end


% --- Executes on button press in checkbox4.
function checkbox4_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
val=get(hObject,'value');
if val==1
    point
end



% Hint: get(hObject,'Value') returns toggle state of checkbox4


% --- Executes during object deletion, before destroying properties.
function pm_course_name_DeleteFcn(hObject, eventdata, handles)
% hObject    handle to pm_course_name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over pm_course_name.
function pm_course_name_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to pm_course_name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

猜你喜欢

转载自blog.csdn.net/qq_24624539/article/details/81462096
今日推荐