如何从Mathematica导出为Excel数字作为文本字段? [英] How to export to Excel numbers as text fields from Mathematica?

查看:43
本文介绍了如何从Mathematica导出为Excel数字作为文本字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含电话号码的列表,格式为"+74951234567",我希望将其导出到Excel,而不用引号将原始外观保留为加号.在Excel中,我可以将单元格格式设置为文本",然后输入+74951234567不带引号不会导致将其转换为数字.是否可以在 Mathematica 中强制导出来创建文本单元格?

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?

我找到了一种方法,该方法可以实现我所希望的:我需要将表导出为XML数据,并添加格式信息.例如,"ss:StyleID"-> XMLElement ["Cell",{"ss:StyleID"->中的"s21" 语句"s21"},{XMLElement ["Data",{"ss:Type"->"String"},{"+74951234567"}]}] 将单元格设置为文本".

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".

通过在Excel中将表另存为"XML表",然后在 Mathematica 导入生成的文件,我发现了这一点:

I have found this by saving the table as "XML Table" from Excel and then Importing the generated file in Mathematica:

XMLData = Import["test.xml", "IncludeNamespaces" -> "Unparsed"]

XMLData 可以在 Mathematica 中进行进一步的修改,然后 Export 倒退为XML:

The XMLData can further be modified inside Mathematica and Exported backward to XML:

Export["test-from MMa.xml", XMLData]

导出的文件由Excel作为普通工作表打开,并且可以按常规方式进行操作.

The exported file is opened by Excel as ordinary worksheet and can be manipulated in the usual manner.

但是我仍然需要帮助,因为我不熟悉XML和 Mathematica 的XML功能.

But I still need help because I am not familiar with XML and Mathematica's XML capabilities.

似乎另一种选择是使用 JExcelAPI 我尚未尝试过的Java库.

It seems that another option would be using JExcelAPI Java library which I have not tried yet.

推荐答案

看起来很简单.在Mathematica中使用引号使Excel将数据解释为文本.

Looks fairly simple. Use quotes in Mathematica to make Excel interpret data as text.

这篇关于如何从Mathematica导出为Excel数字作为文本字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆