创建具有行和列的某些标头的xls或csv文件 [英] Create a xls or csv file with certain header of rows and columns

查看:209
本文介绍了创建具有行和列的某些标头的xls或csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在"UserID"矩阵中有一个ID列表.我想创建一个xls或csv文件,该UserID是其标题行.行数是:2200000,列数是11.列标签是1996-2006年.我阅读了此页面:

I have a list of ID in a matrix 'UserID'. I want create a xls or csv file that this UserID is its header lines. number of rows is:2200000 and number of columns is 11. Label of columns is years of 1996 - 2006 . I read this page :

但是此代码给我错误.尽管有时候行数少了,有时却没有答案,有人可以引入一个程序来做到这一点吗? (使用Matlab甚至是C#代码)

but this code give me error. Although sometimes less is true for the number of rows and sometimes does not answer.Can anyone introduce a program that will do this? (with matlab or even c# code)

我写这段代码:

data=zeros(2200000,11);
data_cells=num2cell(data);
col_header={'1996','1997','1998','1999','2000','2001','2002','2003','2004','2005','2006'};
row_header(1:2200000,1)=UserID;
output_matrix=[{' '} col_header; row_header data_cells];
xlswrite('My_file.xls',output_matrix);

我收到此错误:

指定的数据范围无效或太大,无法写入指定的文件格式.尝试写入XLSX文件,并为范围参数使用Excel A1表示法,例如"A1:D4".

The specified data range is invalid or too large to write to the specified file format. Try writing to an XLSX file and use Excel A1 notation for the range argument, for example, ‘A1:D4’.

推荐答案

使用xlswrite时,您只能使用

数组A的最大大小取决于相关的Excel版本.

The maximum size of array A depends on the associated Excel version.

在Excel 2013中,最大值为1048576,比2200000x11矩阵少1151424行.

In Excel 2013 the maximum is 1048576, which is 1151424 fewer rows than your 2200000x11 matrix.

您最好使用 csvwrite 导出数据,并参考其中的提示:

You better use csvwrite to export your data, and refer also to the tip therein:

csvwrite不接受输入矩阵M的单元格数组.要导出仅包含数字数据的单元格数组,请使用

根据您的情况,您应该至少更改代码的以下部分:

In your case, you should at least change this parts of the code:

col_header = 1996:2006;
output_matrix=[0, col_header; row_header data];

,您无需将output_matrix定义为单元格数组(也不需要data_dells).但是,您可能还必须将UserID转换为数字变量.

and you don't need to define output_matrix as a cell array (and don't need data_dells). However, you may also have to convert UserID to a numeric variable.

这篇关于创建具有行和列的某些标头的xls或csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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