如何把数据库以二进制存储的excel,word文档写入excel,word
来源:互联网 发布:怎么在ubuntu上安装qq 编辑:程序博客网 时间:2024/05/20 07:37
Excel.Application excel = new Excel.Application ();
excel.Application.Workbooks.Add ( true );
string ConnString= "workstation id=WEIXIONG;packet size=4096;integrated security=SSPI;data source=WEIXIONG;persist security info=False;initial catalog=web ";
SqlConnection cn=new SqlConnection(ConnString);
cn.Open();
string s= "select * from ImageStore ";
SqlCommand cmd=new SqlCommand(s,cn);
SqlDataReader dr=cmd.ExecuteReader();
Excel.Application xlApp=new Excel.ApplicationClass();
if(xlApp==null)
{
MessageBox.Show( "Excel錯誤 ");
return;
}
xlApp.Application.Workbooks.Add(true);
while(dr.Read())
{
數據庫裡以二進制存儲了一個excel文檔``我用SqlDataReader讀取了這個文檔```現在要寫入excel裡面```要怎麼搞;
}
xlApp.Visible=true;//打開excel
xlApp=null;
------解决方案--------------------------------------------------------
是不是以流的形式写入数据库的,那就应该以流的形式输出.数据库可不知道你是什么WORD,还是EXCEL的...
string strSQL = "Select [filecontent] from T_autoupdateprogram where filename = ' " + filename + " ' ";
System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand(strSQL,sqlcon);
//reader data from table
System.Data.SqlClient.SqlDataReader sdr = command.ExecuteReader();
//sdr gets data
sdr.Read();
//write io to memory
System.IO.MemoryStream ms = new System.IO.MemoryStream((byte[])sdr[ "filecontent "]);
//record
this.listBox1.Items.Add(filename+ " has been downloaded! ");
//close reader
sdr.Close();
//check file
FileInfo file = new FileInfo(target);
if (file.Exists)
file.Delete();
//file stream
FileStream fs = file.OpenWrite();
//create file
ms.WriteTo(fs);
//close file stream
fs.Close();
//close memorystream
ms.Close();
------解决方案--------------------------------------------------------
将数据读取后,保存成文件。格式嘛,你只要按照二进制格式存储就好。然后存储文件名用.doc或者.xls。然后直接打开。
------解决方案--------------------------------------------------------
以流的方式写进去,用一个字段去表示它是什么格式的,读出来保存成一个文件再加上扩展名
------解决方案--------------------------------------------------------
/// <summary>
/// 将文件转换成二进制流数据
/// </summary>
/// <param name= "path "> 文件的完整路径(包括文件名) </param>
/// <returns> </returns>
public static byte[] GetByteOfFile(string path)
{
FileInfo fi = new FileInfo(path);
FileStream fs = fi.OpenRead();
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, 0, Convert.ToInt32(fs.Length));
return bytes;
}
/// <summary>
/// 将二进制流数据保存为本地文件,如果文件已经存在将删除并重新创建
/// </summary>
/// <param name= "fileName "> 文件的完整路径 </param>
/// <param name= "file "> 二进制流数据 </param>
public static void SaveFile(string fileName, byte[] file)
{
if (File.Exists(fileName))
{
File.Delete(fileName);
}
FileStream fs = new FileStream(fileName, FileMode.CreateNew);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(file, 0, file.Length);
bw.Close();
fs.Close();
}
- 如何把数据库以二进制存储的excel,word文档写入excel,word
- 如何把数据库的内容写入到Word文档中
- 如何把数据库的内容写入到Word文档中?
- 如何把word文档按照单元格放进excel中
- Java如何操作Word, Excel, PDF文档
- Java如何操作Word, Excel, PDF文档
- Java如何操作Word, Excel, PDF文档
- Java如何操作Word, Excel, PDF文档?
- Java如何操作Word, Excel, PDF文档?
- 把word文档写入Sqlserver
- 如何将做好的excel表格转换成word文档
- 如何把数据以Excel文档下载
- 用Python读取Word文档并写入Excel(一)
- 用Python读取Word文档并写入Excel(二)
- 如何用DELPHI实现把WORD、EXCEL和图片等存储到数据库中
- 怎样把数据导出成word文档或者Excel
- 怎样可以把excel表格转换成word文档
- WORD中储存vba代码,把excel数据写入word并保存。
- NYOJ三点顺序 南工68
- 数据结构之线性表1
- 数据库范式详解
- MyEclipse插件安装的几种方式
- 动态规划(3)Pots (BFS)
- 如何把数据库以二进制存储的excel,word文档写入excel,word
- 使用JQuery.js & JQuery.form.js 插件完成对StrutsAction的异步请求,返回JSON数据
- 1113 正/负数统计
- 开发者应该了解的 12 款 Eclipse 插件
- SQL Server默认值中的所有字段的列出
- Type Casting
- Java设计模式之十四(组合模式)
- 最长公共上升子序列(LCIS)的O(n^2)算法
- 1114 计算营业额