Exporting strings to Excel using writetable
Sie verfolgen jetzt diese Frage
- Aktualisierungen können Sie in Ihrem Feed verfolgter Inhalte sehen.
- Je nach Ihren Kommunikationseinstellungen können Sie auch E-Mails erhalten.
Es ist ein Fehler aufgetreten
Da Änderungen an der Seite vorgenommen wurden, kann diese Aktion nicht abgeschlossen werden. Laden Sie die Seite neu, um sie im aktualisierten Zustand anzuzeigen.
0 Stimmen
Teilen Sie einen Link zu dieser Frage
Akzeptierte Antwort
0 Stimmen
Teilen Sie einen Link zu dieser Antwort
15 Kommentare
Teilen Sie einen Link zu diesem Kommentar
Teilen Sie einen Link zu diesem Kommentar
Teilen Sie einen Link zu diesem Kommentar
Teilen Sie einen Link zu diesem Kommentar
Teilen Sie einen Link zu diesem Kommentar
Teilen Sie einen Link zu diesem Kommentar
Teilen Sie einen Link zu diesem Kommentar
Teilen Sie einen Link zu diesem Kommentar
Teilen Sie einen Link zu diesem Kommentar
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')
Teilen Sie einen Link zu diesem Kommentar
Teilen Sie einen Link zu diesem Kommentar
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.
Teilen Sie einen Link zu diesem Kommentar
@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.
Teilen Sie einen Link zu diesem Kommentar
Teilen Sie einen Link zu diesem Kommentar
Teilen Sie einen Link zu diesem Kommentar
Weitere Antworten (0)
Kategorien
Mehr zu Spreadsheets finden Sie in Hilfe-Center und File Exchange
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Website auswählen
Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .
Sie können auch eine Website aus der folgenden Liste auswählen:
So erhalten Sie die bestmögliche Leistung auf der Website
Wählen Sie für die bestmögliche Website-Leistung die Website für China (auf Chinesisch oder Englisch). Andere landesspezifische Websites von MathWorks sind für Besuche von Ihrem Standort aus nicht optimiert.
Amerika
- 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)
