Why is "readtable" taking dimensions from first sheet in excel when using "opts"?
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 18 de Nov. de 2024 a las 0:00
Respondida: MathWorks Support Team
el 20 de Nov. de 2024 a las 18:07
Why is "readtable" using the dimensions of the first sheet in excel when I trying to get data from another sheet?
For example, if the first sheet has 10 rows and 3 columns, second sheet has 15 rows and 7 columns. When I use "readtable" and use "opts" to read all the data from second sheet in "char" format, the output has only 10 rows and 3 columns of the data from second sheet.
Why does this not happen when I don't use "opts" to set import options?
Here is an example code:
eqdFile = 'JUNK2.xlsx';
opts = detectImportOptions(eqdFile);
opts = setvartype(opts,'char');
T = readtable(eqdFile,opts,'Sheet','NameOfSheet')
Respuesta aceptada
MathWorks Support Team
el 18 de Nov. de 2024 a las 0:00
This is an intended behavior. If you do not provide the information about the sheet you want to import data from in the import options, it takes the size of the first sheet.
The following change in the code will resolve this issue:
eqdFile = 'JUNK2.xlsx';
opts = detectImportOptions(eqdFile,'Sheet','NameOfSheet');
opts = setvartype(opts,'char');
T = readtable(eqdFile,opts)
Here, the name of the sheet to import from is mentioned in "detectImportOptions" using the 'Sheet' argument.
If import options ("opts") is not used, "readtable" can get the size of the sheet you are trying to import from correctly and does not default to the size data in the first sheet.
Here is an example to import data from .XLSX file without using "opts":
eqdFile = 'JUNK2.xlsx';
T = readtable(eqdFile,'Sheet','NameOfSheet')
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Spreadsheets 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!