问题
I have a list containing telephone numbers in the form "+74951234567" and I wish to export it to Excel without quotes preserving original appearance with the plus sign. In Excel I can set the cell format to "Text" and then entering +74951234567 without quotes will not result in converting it to number. Is it possible to force Export
in Mathematica to create Text cells?
UPDATE
I have found an approach which allows to get what I wish: I need to export the table as XML data with formatting information added. For example, the "ss:StyleID" -> "s21"
statement in XMLElement["Cell", {"ss:StyleID" -> "s21"}, {XMLElement["Data", {"ss:Type" -> "String"}, {"+74951234567"}]}]
formats the cell as "Text".
I have found this by saving the table as "XML Table" from Excel and then Import
ing the generated file in Mathematica:
XMLData = Import["test.xml", "IncludeNamespaces" -> "Unparsed"]
The XMLData
can further be modified inside Mathematica and Export
ed backward to XML:
Export["test-from MMa.xml", XMLData]
The exported file is opened by Excel as ordinary worksheet and can be manipulated in the usual manner.
But I still need help because I am not familiar with XML and Mathematica's XML capabilities.
UPDATE 2
It seems that another option would be using JExcelAPI Java library which I have not tried yet.
回答1:
Looks fairly simple. Use quotes in Mathematica to make Excel interpret data as text.
回答2:
I don't think what you want is possible at this time, but here's how I'd go about trying it. Try creating a simple spreadsheet with what you want and Import
the FormattedData
element to see what the form of the data should be. Then try exporting the data back using that form.
来源:https://stackoverflow.com/questions/11256618/how-to-export-to-excel-numbers-as-text-fields-from-mathematica