解决方案 »

  1.   

    用excel  分4个sheet也来存。搜索  NPOI
      

  2.   

    请你抛开txt,excel等存储方式,你这样的存储,其实自定义文件格式最方便,比如定义一个List,或者map或者其他的class,然后对其进行序列化和反序列化,很容易的就可以拥有自定义的数据存储
      

  3.   

    你好 我可以 用一个excel吗?
      

  4.   

    不懂  我是搞硬件为主的和下位机嵌入式的所以这一块比较白,能够详细介绍下吗?我肯定要存到电脑的excel 而或txt中,这样我才能够分析采集的数据等等
      

  5.   

    你好 我可以 用一个excel吗?
    可以呀,一个excel,分为多个sheet页,先了解下基本知识。
      

  6.   

    不懂代码,你连操作excel或txt也不懂吗?
    好歹先设计好想要保存成什么格式,然后搜一搜如何用程序去操作对应类型的文件,最后用代码实现排版就行了
    遇到问题学会分解,不要眉毛胡子一把抓
      

  7.   

    你好 我可以 用一个excel吗?
    可以呀,一个excel,分为多个sheet页,先了解下基本知识。
    你好我现在有用excel 我是winform项目 用的 C#   using nopi;  有错误  这是我用的excel  
          //创建Application对象 
                  excelApplication = new Excel.ApplicationClass();              // 打开已有的 excel  名字
                  excelWorkbooks = excelApplication.Workbooks;//工作薄实例声明  
                  excelWorkbook = excelWorkbooks.Open(PAT3, Type.Missing, Type.Missing,
                  Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing) as Excel.Workbook;              // excel.Application.Workbooks.Add(true);              //不存在相同文件,则建立一个新的文件
                  //读取数据,通过Range对象 
                  //Microsoft.Office.Interop.Excel.Range rng1 = excelWorksheet.get_Range("A1", Type.Missing);
                  //Console.WriteLine(rng1.Value2);
                  excelWorksheet = excelWorkbook.Worksheets[5] as Excel.Worksheet;   //设置第几个表   1开始的
                  excelApplication.Visible = false;
                  //读取,通过Range对象,但使用不同的接口得到Range 
                 for (num1 =0;num1<=119;num1++)
                   {
                       excelWorksheet.Cells[num1 + 1, 1] = Convert.ToSingle(strA[num1]) * U2C[num1, 0] * 1000; //PF-->fF                   excelWorksheet.Cells[num1 + 1, 2] = Convert.ToSingle(strB[num1]) * U2C[num1, 0] * 1000; //PF-->fF
                                  }
                 excelWorksheet.Cells[num1 + 1, 1] = "空管标定电容值A";
                 excelWorksheet.Cells[num1 + 1, 2] = "空管标定电容值B";
                 excelWorksheet.Cells[num1 + 3, 1] = DateTime.Now.ToString();
                 excelWorksheet.Cells[num1 + 3, 2] = DateTime.Now.ToString();               try
                   {
                       excelWorkbook.Save();   
                       excelWorksheet = null;
                       excelWorkbook = null;
                       excelWorkbooks = null;
                      // excelRange = null;
                       if (excelApplication != null)
                       {
                           excelApplication.Workbooks.Close();
                           excelApplication.Quit();
                           excelApplication = null;
                       }
                   }
                   catch (Exception ex)
                   {
                       throw new Exception(ex.Message);
                   }
                   finally
                   {
                       showtext5("空管导入excel中结束");
                   }
     
      

  8.   

    要使用NPOI,你需要NPOI的dll,不要网上随便抄一些不完整的代码
    这里有下载,附带例子
      

  9.   

    文本文件对Excel文件的读取和保存
    //读取文本文件到Excel文件
     private void btn_Read_Click(object sender, EventArgs e)
            {
                int P_int_Count=0;//记录正在读取的行数
                string P_str_Line, P_str_Content = "";//记录读取行的内容及遍历到的内容
                List<string> P_str_List = new List<string>();//存储读取的所有内容
                StreamReader SReader = new StreamReader(txt_Txt.Text, Encoding.Default);//实例化流读取对象
                while ((P_str_Line = SReader.ReadLine()) != null)//循环读取文本文件中的每一行
                {
                    P_str_List.Add(P_str_Line);//将读取到的行内容添加到泛型集合中
                    P_int_Count++;//使当前读取行数加1
                }
                Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();//实例化Excel对象
                object missing = System.Reflection.Missing.Value;//获取缺少的object类型值
                //打开指定的Excel文件
                Microsoft.Office.Interop.Excel.Workbook workbook = excel.Application.Workbooks.Open(txt_Excel.Text, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
                Microsoft.Office.Interop.Excel.Worksheet newWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets.Add(missing, missing, missing, missing);
                excel.Application.DisplayAlerts = false;//不显示提示对话框
                for (int i = 0; i < P_str_List.Count; i++)//遍历泛型集合
                {
                    P_str_Content = P_str_List[i];//记录遍历到的值
                    if (Regex.IsMatch(P_str_Content, "^[0-9]*[1-9][0-9]*$"))//判断是否是数字
                        newWorksheet.Cells[i + 1, 1] = Convert.ToDecimal(P_str_Content).ToString("¥00.00");//格式化为货币格式,再添加到工作表中
                    else
                        newWorksheet.Cells[i + 1, 1] = P_str_Content;//直接将遍历到的内容添加到工作表中
                }//codego.net/tags/1/1/
                workbook.Save();//保存工作表
                workbook.Close(false, missing, missing);//关闭工作表
                MessageBox.Show("已经将文本文件内容成功导入Excel工作表中!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
    //将Excel文件读取到文本文件
      private void btn_Txt_Click(object sender, EventArgs e)
            {
                //连接Excel数据库
                OleDbConnection olecon = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + txt_Path.Text + ";Extended Properties=Excel 8.0");
                olecon.Open();//打开数据库连接
                OleDbDataAdapter oledbda = new OleDbDataAdapter("select * from [" + cbox_SheetName.Text + "$]", olecon);//从工作表中查询数据
                DataSet myds = new DataSet();//实例化数据集对象
                oledbda.Fill(myds);//填充数据集
                StreamWriter SWriter = new StreamWriter(cbox_SheetName.Text + ".txt", false, Encoding.Default);//实例化写入流对象
                string P_str_Content = "";//存储读取的内容
                for (int i = 0; i < myds.Tables[0].Rows.Count; i++)//遍历数据集中表的行数
                {
                    for (int j = 0; j < myds.Tables[0].Columns.Count; j++)//遍历数据集中表的列数
                    {
                        P_str_Content += myds.Tables[0].Rows[i][j].ToString() + "  ";//记录当前遍历到的内容
                    }
                    P_str_Content += Environment.NewLine;//字符串换行
                }
                SWriter.Write(P_str_Content);//先文本文件中写入内容
                SWriter.Close();//关闭写入流对象
                SWriter.Dispose();//释放写入流所占用的资源
                MessageBox.Show("已经将" + cbox_SheetName.Text + "工作表中的数据成功写入到了文本文件中", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
      

  10.   

    http://blog.csdn.net/xianfajushi/article/details/8093957
      

  11.   

     你的意思是先在线保存到 txt,然后通过线下转到EXCEL中对吗??
      

  12.   

    谢谢 ,我现在 理理思路 ,首先我的传输速度不慢几百KB/S,这里如果用excel 来保存速度基本上跟不上,我是这么觉得,所以我现在还是用stremwriter txt 来存数据, 存好数据后线下转换所需要的数据到对应的EXCEL中,不知道是不是这个意思,还有想问下操作npoi他是覆盖 而不是添加 ,不知道可不可以append,我用excel excelApplication = new Excel.ApplicationClass();            // 打开已有的 excel  名字
                excelWorkbooks = excelApplication.Workbooks;//工作薄实例声明  
                excelWorkbook = excelWorkbooks.Open(PAT1 , Type.Missing, Type.Missing,
                   Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing) as Excel.Workbook;
                showtext5("开始保存" + "...");
                excelWorksheet = excelWorkbook.Worksheets[10] as Excel.Worksheet;   //设置第几个表   1开始的
                excelApplication.Visible = false;
    来读写就可以,而先前的数据也还在  
      

  13.   

    NPOI可以打开现有文件,也可以create新行啊
    不要给已有的单元格赋值不就不覆盖了