Adding a row to an existing ones in Excel

조회 수: 2 (최근 30일)
Cristian Martin
Cristian Martin 2022년 6월 4일
댓글: Cristian Martin 2022년 6월 4일
Hi guys,
I have to write some data to an excel after getting them from an edit text and from a column of an uitable
tableDatanew = get(handles.uitable4, 'data');
tableDatacoloane = cell2table(tableDatanew);
tableDatacoloane1 = tableDatacoloane{1,2:2};% taking the date
date = char(tableDatacoloane1);
intrari_a = get(handles.edit3,'String');% taking a number
intrari_b = get(handles.edit4,'String');% taking a number
intrari_c = get(handles.edit5,'String');% taking a number
total = get(handles.edit2,'String');% taking a number
grafic1 = {date intrari_a intrari_b intrari_c total};
%disp(grafic1);
%'01.02.2021' '1' '3' '2' '6'
grafic2 = readtable('grafic\grafic.xlsx');%read old datas from tables
new_data = [grafic2; grafic1];%combining new and old
writetable(new_data, 'grafic\grafic.xlsx','Sheet',1,'Range','A2','WriteVariableNames',0);
%For the first input in excel display(new_data) looks like this:
A B C D E
____________ ___ ___ ___ ___
'01.02.2021' '1' '3' '2' '6'
%For the second input in excel display(new_data) looks like this:
A B C D E
____________ ___ ___ ___ ___
'01.02.2021' [1] [3] [2] [6]
'01.02.2021' '1' '3' '2' '6'
%the problem i guess is somewere in tableread variable B to E ....
%For the third input in excel error is this:
Cannot concatenate the table variable 'B' because it is a cell in one table and a non-cell in another.
  댓글 수: 1
Cristian Martin
Cristian Martin 2022년 6월 4일
The problem was from not converting the edittext values to double
intrari_a = str2double(get(handles.edit3,'String'));
intrari_b = str2double(get(handles.edit4,'String'));
intrari_c = str2double(get(handles.edit5,'String'));
total = str2double(get(handles.edit2,'String'));

댓글을 달려면 로그인하십시오.

답변 (1개)

Benjamin Thompson
Benjamin Thompson 2022년 6월 4일
I cannot review online documentation for releases earlier than R2017A, but in that release readtable supports a 'TextType' option to convert input strings as 'char' or 'string'. Or try the 'Format' option if you want to read in from Excel as numbers. Either way you need to get the data types you read in from Excel to match what you are reading in from your UI so that the table concatenation will work.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by