Export Data to Excel Error:
Mostrar comentarios más antiguos
I have three different output arrays as low voltage, med voltage and high voltage. Three arrays have different number of rows. I want to export three arrays as three different columns of same excel sheet.I tried to use the writetable, but after one writetable command, it is giving error
"Unable to write to file 'FlowDistinction_Yearly.xlsx'. You may not have write permissions or the file may be open by another
application."
Code:
filename = 'FlowDistinction_Yearly.xlsx'
writetable(array2table(High),filename,'sheet',1,'Range','A1:')
writetable(array2table(Med),filename,'sheet',1,'Range','A2:')
I checked few other options but most of them require same number of rows but in my case, number of rows will be different for each column.
1 comentario
Harjas
el 30 de Jun. de 2022
Respuesta aceptada
Más respuestas (2)
Cris LaPierre
el 30 de Jun. de 2022
Editada: Cris LaPierre
el 30 de Jun. de 2022
I am able to reproduce the error in R2018b. This appears to be an issue that has been fixed in newer versions of MATLAB. Any chance you can update your MATLAB version?
Note that, to write your data , I think you want the following Range syntax
writetable(array2table(High),filename,'sheet',1,'Range','A:A')
writetable(array2table(Med),filename,'sheet',1,'Range','B:B')
4 comentarios
Harjas
el 30 de Jun. de 2022
Cris LaPierre
el 1 de Jul. de 2022
Editada: Cris LaPierre
el 1 de Jul. de 2022
Ok, I asked internally and the recommendation was to add the 'UseExcel',false name-value pair, which fixed the error for me. In R2018 the default is true. In R2019 and on, the default is now false.
writetable(array2table(High),filename,'sheet',1,'Range','A:A','UseExcel',false)
writetable(array2table(Med),filename,'sheet',1,'Range','B:B','UseExcel',false)
Harjas
el 4 de Jul. de 2022
Image Analyst
el 4 de Jul. de 2022
Otherwise take out the 'UseExcel' parameter. If you still want an .xlsx format workbook created but for some reason do not want Excel to be used, then call tech support and ask them why UseExcel is not working. The UseExcel = false should work for these formats: .xls, .xlsx, .xlsm, .xltx, .xltm
Image Analyst
el 30 de Jun. de 2022
Maybe the workbook is still locked because the first call to writetable() has not finished 100%. If you put
pause(2); % Wait 2 seconds for writetable to finish.
in between the calls to writetable, does it work then?
3 comentarios
Cris LaPierre
el 30 de Jun. de 2022
Editada: Cris LaPierre
el 30 de Jun. de 2022
It didn't help me. I had to kill the process and delete the workbook, and even then, it wasn't behaving as I would expect.
Image Analyst
el 1 de Jul. de 2022
No problem. Please click "Accept this answer" on his answer below to award him reputation points.
Categorías
Más información sobre Spreadsheets en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!