首页 > Windows开发 > 详细

C#写入excel和txt

时间:2014-12-30 18:29:07      阅读:344      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!