
/// <summary>
/// base64编码的文本转为图片
/// </summary>
/// <param name="txtFilePath">文件相对路径(存到服务器上)</param>
/// <param name="str">图片字符串</param>
private void Base64StringToImage(string txtFilePath, string str)
{
try
{
String inputStr = str
byte[] arr = Convert.FromBase64String(inputStr)
MemoryStream ms = new MemoryStream(arr)
Bitmap bmp = new Bitmap(ms)
bmp.Save(System.Web.HttpContext.Current.Server.MapPath(txtFilePath) + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
//bmp.Save(txtFileName + ".bmp", ImageFormat.Bmp)
//bmp.Save(txtFileName + ".gif", ImageFormat.Gif)
//bmp.Save(txtFileName + ".png", ImageFormat.Png)
ms.Close()
//imgPhoto.ImageUrl = txtFilePath + ".jpg"
//MessageBox.Show("转换成功!")
}
catch (Exception ex)
{
}
} public void ExportControl(System.Web.UI.Control source, string DocumentType, string filename)
{
//设置Http的头信息,编码格式
HttpContext.Current.Response.Buffer = true
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ClearContent()
HttpContext.Current.Response.ClearHeaders()
if (DocumentType.ToLower() == "excel")
{
//Excel
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachmentfilename=" + HttpUtility.UrlEncode(filename + ".xls", System.Text.Encoding.UTF8))
HttpContext.Current.Response.ContentType = "application/ms-excel"
}
else if (DocumentType.ToLower() == "word")
{
//Word
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachmentfilename=" + HttpUtility.UrlEncode(filename + ".doc", System.Text.Encoding.UTF8))
HttpContext.Current.Response.ContentType = "application/ms-word"
}
HttpContext.Current.Response.Charset = "UTF-8"
HttpContext.Current.Response.HeaderEncoding=System.Text.Encoding.UTF8
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8
//关闭控件的视图状态
source.Page.EnableViewState = false
//初始化HtmlWriter
System.IO.StringWriter writer = new System.IO.StringWriter()
System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(writer)
source.RenderControl(htmlWriter)
//输出
HttpContext.Current.Response.Write(writer.ToString())
HttpContext.Current.Response.End()
}
3、将SQL SERVER中查询到的数据导成一个Excel文件T-SQL代码:
EXEC master..xp_cmdshell 'bcp 库名.dbo.表名out c:\Temp.xls -c -q -S"servername" -U"sa" -P""'
参数:S 是SQL服务器名;U是用户;P是密码
说明:还可以导出文本文件等多种格式
实例:EXEC master..xp_cmdshell 'bcp saletesttmp.dbo.CusAccount out c:\temp1.xls -c -q -S"pmserver" -U"sa" -P"sa"'
EXEC master..xp_cmdshell 'bcp "SELECT au_fname, au_lname FROM pubs..authors ORDER BY au_lname" queryout C:\ authors.xls -c -Sservername -Usa -Ppassword'
在VB6中应用ADO导出EXCEL文件代码:
Dim cn As New ADODB.Connection
cn.open "Driver={SQL Server}Server=WEBSVRDataBase=WebMisUID=saWD=123"
cn.execute "master..xp_cmdshell 'bcp "SELECT col1, col2 FROM 库名.dbo.表名" queryout E:\DT.xls -c -Sservername -Usa -Ppassword'"
先导入到excel里面在拷贝的word里面 这样就可以打印不是吗
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)