Exporting strings to Excel using writetable
Ahora está siguiendo esta pregunta
- Verá actualizaciones en las notificaciones de contenido en seguimiento.
- Podrá recibir correos electrónicos, en función de las preferencias de comunicación que haya establecido.
Se ha producido un error
No se puede completar la acción debido a los cambios realizados en la página. Vuelva a cargar la página para ver el estado actualizado.
0 votos
Comparte un enlace a esta pregunta
Respuesta aceptada
0 votos
Comparte un enlace a esta respuesta
15 comentarios
Comparte un enlace a este comentario
Comparte un enlace a este comentario
Comparte un enlace a este comentario
Comparte un enlace a este comentario
Comparte un enlace a este comentario
Comparte un enlace a este comentario
Comparte un enlace a este comentario
Comparte un enlace a este comentario
Comparte un enlace a este comentario
Walter's last comment about ActiveX is on the right track. With both xlswrite and writetable, if Excel is available, MATLAB will launch it and communicate to the running Excel process to write the data. On Mac (or if you don't have Excel) writetable uses a different method to write the excel file.
In the Excel application, writing text into a cell does some things in the background. If you type "9" in a cell, Excel turns that into a number. If you write a date that Excel recognizes, it will format that cell as a date. The same thing is happening when writetable is using Excel. This occurs in the Excel process, so there's nothing MATLAB can do about it. =/
When not using Excel, there's no opportunity for the type to change, so you get the exact thing from the table.
Does the same thing happen with string?
myString = ["'Abcd";"'493E07";"'Sep7"]; myTable = table(myString); writetable(myTable,'myTable.xls')
Comparte un enlace a este comentario
Comparte un enlace a este comentario
Jeremy, thanks for the suggestion to try string. When I execute those commands, it produces the same result as if I generate the table from the cell array—it writes each string to Excel with two leading single quotes instead of one.
Comparte un enlace a este comentario
@Jeremy Hughes,
I'm afraid that the present issue is a bug in matlab, not a problem with excel. Consider the following codes
- using direct actxserver
excel = actxserver('Excel.Application'); %start excel
wb = excel.Workbooks.Add
wb.Worksheets.Item(1).Range('A1').Value = '''aaa';
wb.SaveAs(fullfile(pwd, 'xlactx.xls'))
excel.Quit
- using vbscript (invoked outside matlab via cscript)
Set excel = CreateObject("Excel.Application")
Set wb = excel.Workbooks.Add
wb.Worksheets(1).Range("A1").Value = "'aaa"
wb.SaveAs("C:\users\guillaume\Documents\MATLAB\answers\xlvbs.xls")
excel.Quit
- using writetable
t = table({'''aaa'});
writetable(t, 'xltable.xlsx', 'WriteVariableNames', false)
The last one results in the doubling of the ' in the excel file. The first two don't.
Unfortunately, because the actual workbook handling code is a built-in class of matlab, it's not possible for us to know what is going wrong.
Comparte un enlace a este comentario
Comparte un enlace a este comentario
Comparte un enlace a este comentario
Más respuestas (0)
Categorías
Más información sobre Spreadsheets en Centro de ayuda y File Exchange.
Etiquetas
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.
América
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
