c# 在wince上 读excel csv txt 的方法

在wince 上对excel 文件的支持比较少,读比较麻烦,可以把excel 文件另存为csv文件,csv文件可以改后缀变成txt文件。

读txt的时候用 string.splite 分隔之下面是我自己写的只读的类

using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Reflection;

namespace demo_rfcom_wince
{
    class csvFile
    {
        private  StreamReader m_StreamReader;
        private string[] m_StrArry;
        private int m_FileLinesCount = 0;
        public csvFile(string name)
        {
            string cvsFileName;
            cvsFileName  =  System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName)+"\\"+name;
            m_StreamReader = new StreamReader(cvsFileName, Encoding.Default);
            while(m_StreamReader.ReadLine()!=null)m_FileLinesCount++;
            m_StrArry = new string[m_FileLinesCount+1];

            //load
            int i;
            m_StreamReader.BaseStream.Position = 0;
            for (i = 0; i < m_FileLinesCount; i++)m_StrArry[i] = m_StreamReader.ReadLine();
        }
        ~csvFile()
        {
            m_StreamReader.Close();
        }
        public int GetLinesCount()
        {
            return m_FileLinesCount;
        }
        public string Read(int x, int y)
        {
            if (y > m_FileLinesCount) return null;
            string[] r = new string[128];
            r = m_StrArry[y].Split(',');
            return r[x];
        }
    }
}


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值