码迷,mamicode.com
首页 > Windows程序 > 详细

C#写入excel和txt

时间:2014-12-30 18:32:19      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:

 

写入txt:           

             string path = Server.MapPath("~/") + "\\Content\\删除记录.txt";           

             string w = DateTime.Now.ToString() + "----" + zfry.userid + "----" + zfry.username;
            w += "----" + zfry.ssqmc + "----" + zfry.bmmc + "----" + qymc + "----" + qydz;
            StreamWriter sw =System.IO.File.AppendText(path);
            sw.WriteLine(w);
            sw.Close();

写入excel:

            string path = Server.MapPath("~/") + "\\Content\\删除记录.txt";
            HSSFWorkbook hssfWorkbook = new HSSFWorkbook(new FileStream(path, FileMode.Open));
            HSSFSheet sheet = (HSSFSheet)hssfWorkbook.GetSheetAt(0);
            int i = sheet.LastRowNum;
            HSSFRow row = (HSSFRow)sheet.CreateRow(i+1);
            row.CreateCell(0).SetCellValue(DateTime.Now.ToString());
            FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            hssfWorkbook.Write(fs);

C#写入excel和txt

标签:

原文地址:http://www.cnblogs.com/forthelichking/p/4193997.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!