saving excel file as a new sheet in another excel file using matlab

조회 수: 23(최근 30일)
Sai Ganesh  Erva Ram
Sai Ganesh Erva Ram 2016년 8월 3일
답변: meghannmarie 2019년 9월 30일
How can i save a excel file (which contains only 1 sheet,i.e template with chart and formatting) as a sheet in the existing excel file using matlab
I tried some examples using activex but it copies only the cells from the file,
The following code is from Matlab forums which saves a copy of the same excel file with different name
I am expecting that my file is copied into a different excel file as a sheet with all the formatting and charts
close all
clear all
% Opens the data analysis template
% Initiates Excel COM Object
Excel = actxserver ('Excel.Application');
set(Excel, 'Visible', 1);
% Allows user to select output file
Exportdir=uigetdir('','Please select export directory');
prompt = {'Please enter EXCEL File name:'};
name = 'Data Output';
numlines = 1;
defaultanswer = {['fianl','_','report']};
options.Resize = 'on';
options.WindowStyle = 'normal';
options.Interpreter = 'tex';
FileName = cell2mat(inputdlg(prompt,name,numlines,defaultanswer,options));
% Saves the template to the user selected output file
invoke(template, 'Close');
% Quit Excel
invoke(Excel, 'Quit');
% End process


Pruthvi G
Pruthvi G 2019년 9월 30일

meghannmarie 2019년 9월 30일
This will copy workseet from InputExcel and paste it after last sheet in OutputExcel:
InputExcel = 'D:\Answers\input.xlsx';
OutputExcel = 'D:\Answers\output.xlsx';
Excel = actxserver ('Excel.Application');
InputExcelWorkbook = Excel.workbooks.Open(InputExcel); % Excel 2010+
OutputExcelWorkbook = Excel.workbooks.Open(OutputExcel);
count = OutputExcelWorkbook.Sheets.Count;
Excel.Quit; % Quit excel application
delete(Excel); % Delete the handle to the application

Community Treasure Hunt

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

Start Hunting!

Translated by