excel文件中的Matlab行数 [英] Matlab number of rows in excel file

查看:383
本文介绍了excel文件中的Matlab行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有Matlab的命令来获取excel文件中写入的行数?
首先填写第一行。然后我想在excel文件中添加另一行。
所以这是我的excel文件:



我试过:

  e = actxserver('Excel.Application'); 
filename = fullfile(pwd,'example2.xlsx');
ewb = e.Workbooks.Open(filename);
esh = ewb.ActiveSheet;

sheetObj = e.Worksheets.get('Item','Sheet1');
num_rows = sheetObj.Range('A1')。End('xlDown')。行

但是num_rows = 1048576,而不是1.
请帮助,谢谢!

解决方案

如果文件是空,或仅包含一行,然后 .End('xlDown')。Row; 将移动到工作表的最底部( 1048576 是Excel 2007+表中的行数)。



测试如果单元格 A2 首先为空,并返回 0 如果是。



或从表格底部使用向上

  num_rows = sheetObj.Cells(sheetObj.Rows.Count,1).End('xlUp')。行

注意:我不确定Matlab语法,所以这可能需要一些调整


is there a command of Matlab to get the number of the written rows in excel file? firstly, I fill the first row. and then I want to add another rows in the excel file. so this is my excel file:

I tried:

e = actxserver ('Excel.Application');
filename = fullfile(pwd,'example2.xlsx');
ewb = e.Workbooks.Open(filename);
esh = ewb.ActiveSheet;

sheetObj = e.Worksheets.get('Item', 'Sheet1');
num_rows = sheetObj.Range('A1').End('xlDown').Row

But num_rows = 1048576, instead of 1. please help, thank you!

解决方案

If the file is empty, or contains data in only one row, then .End('xlDown').Row; will move to the very bottom of the sheet (1048576 is the number of rows in a Excel 2007+ sheet).

Test if cell A2 is empty first, and return 0 if it is.

Or use Up from the bottom of the sheet

num_rows = sheetObj.Cells(sheetObj.Rows.Count, 1).End('xlUp').Row 

Note: I'm not sure of the Matlab syntax, so this may need some adjusting

这篇关于excel文件中的Matlab行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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