c# byte转docx

问题情境:

  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。

猜你喜欢

转载自www.cnblogs.com/gaara-zhang/p/9774521.html