我的做法:
1.生成数据流插入到数据库中的image字段
2.生成word文档
while (reader.Read())
{
fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write);
bw = new BinaryWriter(fs);
startIndex = 0;
//将字节流读入outbyte缓冲区中并返回读取的字节数
reval = reader.GetBytes(0, startIndex, outbyte, 0, buffersize);
//当读取的字节流达到缓冲区允许的最大长度时要卸载缓冲区内的数据并将数据写入文件
while (reval == buffersize)
{
bw.Write(outbyte);
bw.Flush();
//重新设定开始读取的位置,并继续读取和写数据
startIndex += buffersize;
reval = reader.GetBytes(0, startIndex, outbyte, 0, buffersize);
}
//将缓冲区内最后剩余的数据写入文件
bw.Write(outbyte, 0, (int)reval - 1);
bw.Flush();
bw.Close();
fs.Close();
} 可以正常生成word文档。
但生成后手动打开。会有错误提示:‘文件已损坏,无法打开’3.打开word <a href="yit.docx" target="_blank">open</a>
Response.Redirect("yit.docx"); 我在windows 7 & ie8下执行这述代码时。
有跑出一个提示框“打开,保存,取消”
可是我点打开后。它要嘛是无反应。要嘛就会变成一个压缩档 yit.zip 但我在FF下是可以正常打开的。各位大大有遇到这样的情况吗。或者知道怎么解决吗?
感谢先~
1.生成数据流插入到数据库中的image字段
2.生成word文档
while (reader.Read())
{
fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write);
bw = new BinaryWriter(fs);
startIndex = 0;
//将字节流读入outbyte缓冲区中并返回读取的字节数
reval = reader.GetBytes(0, startIndex, outbyte, 0, buffersize);
//当读取的字节流达到缓冲区允许的最大长度时要卸载缓冲区内的数据并将数据写入文件
while (reval == buffersize)
{
bw.Write(outbyte);
bw.Flush();
//重新设定开始读取的位置,并继续读取和写数据
startIndex += buffersize;
reval = reader.GetBytes(0, startIndex, outbyte, 0, buffersize);
}
//将缓冲区内最后剩余的数据写入文件
bw.Write(outbyte, 0, (int)reval - 1);
bw.Flush();
bw.Close();
fs.Close();
} 可以正常生成word文档。
但生成后手动打开。会有错误提示:‘文件已损坏,无法打开’3.打开word <a href="yit.docx" target="_blank">open</a>
Response.Redirect("yit.docx"); 我在windows 7 & ie8下执行这述代码时。
有跑出一个提示框“打开,保存,取消”
可是我点打开后。它要嘛是无反应。要嘛就会变成一个压缩档 yit.zip 但我在FF下是可以正常打开的。各位大大有遇到这样的情况吗。或者知道怎么解决吗?
感谢先~
Response.Redirect("yit.docx"); 这样子的代码都是可以执行下去。但是弹出来的对话框后确打不开word
那为什么打开 docx文件时。默认会变成zip?
打开各种程序的代码-----全!