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

c# byte转docx

时间:2018-10-11 21:59:52      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:files   save   convert   creat   writer   数组   问题   public   sts   

问题情境:

  docx文件放进resource中,再用程序读出来的时候是二进制数组。

解决办法:

public string ByteConvertWord(byte[] data, string fileName)
        {
            string savePath = @"\\" + fileName + ".docx";
            string filePath = Application.StartupPath + savePath;
            FileStream fs;
            if (System.IO.File.Exists(filePath))
            {
                fs = new FileStream(filePath, FileMode.Truncate);
            }
            else
            {
                fs = new FileStream(filePath, FileMode.CreateNew);
            }
            BinaryWriter br = new BinaryWriter(fs);
            br.Write(data, 0, data.Length);
            br.Close();
            fs.Close();
            return filePath;
        }

 问题实质:

  还是IO流读写问题,通过文件可以还原保存为多种格式,包括docx。

c# byte转docx

标签:files   save   convert   creat   writer   数组   问题   public   sts   

原文地址:https://www.cnblogs.com/gaara-zhang/p/9774521.html

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