在控制台读取Excel的方法,可根据自身需要修改使用以适应其它平台使用。
2016-10-02 10:37
295 查看
string filepath = @"D:\wAngran's\文档\Desktop\tempS\亲情1+1_isProc.xlsx";
Microsoft.Office.Interop.Excel.Application ea = new ApplicationClass();
ea.Workbooks.Open(filepath, 3, true, 2, string.Empty, string.Empty, true, XlPlatform.xlWindows, ";", null, null, null, null, null, null);
Workbook wb = ea.Workbooks[1];
Worksheet ws = (Worksheet)wb.Sheets[2];
Microsoft.Office.Interop.Excel.Range re = ws.UsedRange;
int down = re.get_End(Microsoft.Office.Interop.Excel.XlDirection.xlDown).Row;
int right = re.get_End(Microsoft.Office.Interop.Excel.XlDirection.xlToRight).Column;
for (int row_index = 1; row_index < down; row_index++)
{
for (int cel_index = 1; cel_index < right; cel_index++)
{
re = (Range)ws.Cells[row_index, cel_index];
Console.Write(re.Text + "\t");
//re.set_Value(null, cel_index);
}
Console.Write("\n");
}
//if (System.IO.File.Exists(filepath))
// System.IO.File.Delete(filepath);
wb.Close(true, filepath, null);
Microsoft.Office.Interop.Excel.Application ea = new ApplicationClass();
ea.Workbooks.Open(filepath, 3, true, 2, string.Empty, string.Empty, true, XlPlatform.xlWindows, ";", null, null, null, null, null, null);
Workbook wb = ea.Workbooks[1];
Worksheet ws = (Worksheet)wb.Sheets[2];
Microsoft.Office.Interop.Excel.Range re = ws.UsedRange;
int down = re.get_End(Microsoft.Office.Interop.Excel.XlDirection.xlDown).Row;
int right = re.get_End(Microsoft.Office.Interop.Excel.XlDirection.xlToRight).Column;
for (int row_index = 1; row_index < down; row_index++)
{
for (int cel_index = 1; cel_index < right; cel_index++)
{
re = (Range)ws.Cells[row_index, cel_index];
Console.Write(re.Text + "\t");
//re.set_Value(null, cel_index);
}
Console.Write("\n");
}
//if (System.IO.File.Exists(filepath))
// System.IO.File.Delete(filepath);
wb.Close(true, filepath, null);
相关文章推荐
- C#导出Excel的函数(可根据实际需要进行相应修改)
- 使用Excel的VBA来读取和修改bmp位图像素数据
- 使用libzip读取修改zip文件comment的方法(支持添加扩展字符)
- opencv使用日记之一:平台搭建Mat类以及图像的读取修改
- C#使用Ado.net读取Excel表的方法
- Inputstream读取文件,使用read()方法,判断尾标记需要注意的问题
- 使用jxl工具包生成Excel以及读取Excel的方法
- 注册no-ip动态域名以及使用方法,也适用其它Linux平台
- selenium+python关于登录的脚本代码,使用了读取excel以及向excel中写入测试结果的方法
- Python使用xlrd读取Excel格式文件的方法
- ZK框架简介,以及在ZK下使用JXL读取Excel模板,导出数据模型到Excel的方法
- VC++ 中操作Excel文档的方法,读取,查询,写入,修改,删除
- BasicExcel使用方法,VC读取Excel方法
- Python使用xlrd读取Excel格式文件的方法
- 技术转载(鼠标点击X窗口关闭IE的同时清空session,最基本的就是处理用户重复登陆需要用到,我想这个的关键在于如何捕捉到关闭IE这个动作,之后再根据自身的需要使用session.invalidate()或者session.removeAttribute( "xxx "))
- 下载文件使用缓存(一次性读取到内存),优化性能(注意静态对象修改需要加锁)
- 使用Eclipse修改JSP页面需要重启tomcat的解决方法
- VC++ 中操作Excel文档的方法,读取,查询,写入,修改,删除
- java使用POI读取properties文件并写到Excel的方法
- solr-用mmseg4j配置同义词索引和检索(IKanlyzer需要修改源码适应solr接口才能使用同义词功能)