Exporting strings to Excel using writetable
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
채택된 답변
댓글 수: 15
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')
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.
@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.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- 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)
