如何读取/转换Excel XML文件到R / CSV? [英] How to read/convert Excel XML files to R/CSV?

查看:405
本文介绍了如何读取/转换Excel XML文件到R / CSV?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几百个XML文件。它们可能是从/到Excel生成的。我想读它到R或转换为CSV。所有文件的标题都如下所示:

 <?xml version =1.0encoding =UTF-8? ; 
<?mso-application progid =Excel.Sheet?>
< Workbook xmlns =urn:schemas-microsoft-com:office:spreadsheet
xmlns:o =urn:schemas-microsoft-com:office:office
xmlns:x =urn:schemas-microsoft-com:office:excel
xmlns:ss =urn:schemas-microsoft-com:office:spreadsheet
xmlns:html =http: w3.org/TR/REC-html40\">
< DocumentProperties xmlns =urn:schemas-microsoft-com:office:office>

我可以随时写解析器,但是想避免这样做。我没有Excel

解决方案

R Data Import / Export手册中有一个章节使用R安装的手册)从Excel电子表格中读取数据。如果上述XML文件是来自最新版本的Excel的保存的电子表格,那么其中一些工具应该很容易阅读。我可能会从RODBC包或XLConnect包开始。



如果这些不工作,那么XML包应该至少让编写解析器更容易。 / p>

I have few hundred XML files. They are probably generated from/to Excel. I would like to read it to R or convert to CSV. Headers of all files look like this:

<?xml version="1.0" encoding="UTF-8"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:o="urn:schemas-microsoft-com:office:office"
 xmlns:x="urn:schemas-microsoft-com:office:excel"
 xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">

I can always write parser, but would like to avoid doing it. I don't have Excel

解决方案

There is a chapter in the "R Data Import/Export" manual (one of the free manuals that installs with R) on reading data from Excel spreadsheets. If the above XML file is a saved spreadsheet from recent versions of Excel then some of those tools should read them easily. I would probably start with either the RODBC package or the XLConnect package.

If those don't work then the XML package should at least make writing the parser much easier.

这篇关于如何读取/转换Excel XML文件到R / CSV?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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