zoukankan      html  css  js  c++  java
  • fpspread实现Excel导入

    private DataTable GetExcel(string filepach)
            {
                string str;
                FarPoint.Win.Spread.FpSpread fpSpread1 = new FarPoint.Win.Spread.FpSpread();

                try
                {
                    fpSpread1.OpenExcel(filepach);
                }
                catch
                {
                    string filepath1=Path.GetTempPath() + "//"+ Path.GetFileName(filepach);
                    File.Copy(filepach,filepath1) ;
                    fpSpread1.OpenExcel(filepath1);
                    File.Delete(filepath1);
                }
                DataTable dt = new DataTable();
                for (int k = 1; k <= fpSpread1.Sheets[0].GetLastNonEmptyColumn(FarPoint.Win.Spread.NonEmptyItemFlag.Data) + 1; k++)
                {
                    dt.Columns.Add("col" + k.ToString());
                }


                for (int i = 0; i < fpSpread1.Sheets[0].GetLastNonEmptyRow(FarPoint.Win.Spread.NonEmptyItemFlag.Data) + 1; i++)
                {
                    DataRow dr = dt.NewRow();
                    str = "";
                    for (int j = 0; j < fpSpread1.Sheets[0].GetLastNonEmptyColumn(FarPoint.Win.Spread.NonEmptyItemFlag.Data) + 1; j++)
                    {
                        str = str + fpSpread1.Sheets[0].Cells[i, j].Text;
                        dr[j] = fpSpread1.Sheets[0].Cells[i, j].Text;
                    }
                    if (str != "")
                        dt.Rows.Add(dr);

                }
                return dt;

  • 相关阅读:
    在web应用中使用MEF插件式开发
    IBatis更名为mybatis
    ssh公钥登录
    android摄像头获取图像——第二弹
    android摄像头获取图像——第一弹
    堆排序
    配置开发环境及相关问题
    android摄像头获取图像——第三弹
    冒泡排序
    Linux中环境变量文件及配置
  • 原文地址:https://www.cnblogs.com/laojiefang/p/2323777.html
Copyright © 2011-2022 走看看