电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

从数据库中导出图片插入到Excel

12页
  • 卖家[上传人]:洪易
  • 文档编号:40499654
  • 上传时间:2018-05-26
  • 文档格式:DOC
  • 文档大小:72KB
  • / 12 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • 1、1.请问如何把 sqlserver 数据库中的图片导入到 excel 的指定表格中打印?数据表有“photo”的字段保存了图片,先想把图片导出到 excel 中打印,需指定 excel 的表格,入 C3 中打印!以下是我用的方法,贴出来,其他人如用到的可参考一下 思路:先从数据库中把图片保存到根目录中(文件名:temp.jpg) ,然后从 excel 中导入该图片,导入后删除 temp.jpgIf Not IsNull(mRst(“photo“) Then读取显示数据库中的图像Set StmPic = New ADODB.StreamWith StmPic.Type = adTypeBinary.Open.Write mRst.Fields(“photo“) 写入数据库中的数据至 Stream 中 .SaveToFile StrPicTemp, adSaveCreateOverWrite.SaveToFile App.Path using System.IO;using System.Data;using System.Drawing;using System.Drawing.Imag

      2、ing;using System.Windows.Forms;using Excel;private void EduceExcel()string picPath=Directory.GetCurrentDirectory()+Excelpic.jpg;string ExcelName=Directory.GetCurrentDirectory()+ExcelModul.xls;string fileName = Excel+DateTime.Now.ToString().Replace(:, ) + .xls;Excel.Application app =new Excel.Application();/建立 Excel 对象app.Visible=true;/让 Excel 文件可见Workbook objbook;objbook = app.Workbooks.Add(ExcelName);Worksheet worksheet;worksheet =(Worksheet)objbook.Worksheets1;Excel.Pictures pics=(Excel.Pictur

      3、es)worksheet.Pictures(Type.Missing);/建立图片集合对象int TD=1;int p=1;PicItemColletion picItems= PicItem.Getpictems();/读取数据库图片数据集合foreach(PicItem PI in picItems)if(PI.ImageData != null)MemoryStream stream = new MemoryStream(PI.ImageData, 0, PI.ImageData.Length);Bitmap bitmap = new Bitmap(stream);bitmap.Save(picPath,System.Drawing.Imaging.ImageFormat.Jpeg);/保存临时图片文件到硬盘里if(File.Exists(picPath)stream.Close();/关闭图像文件流Range range_1 =range=worksheet.get_Range(A+TD.ToString(),A+TD.ToString();/获取填充单元格范围pics.Ins

      4、ert(picPath,Type.Missing);/获取图片Excel.Picture pic = (Excel.Picture )pics.Item(p);/建立图片集合某一图片对象pic.Left = (double)range_1.Left;pic.Top = (double)range_1.Top;pic.Height =(double)range_1.Height;pic.Width =(double)range_1.Width;TD=TD+1;p=p+1; if(File.Exists(picPath)File.Delete(picPath);/删除图片 3.请教各位:我想用 c#,通过闹钟实现定时把 sqlserver 的数据导入到一个 excel 文件,同时生成一个 EXCEL 文件, 不是手动保存,那位大侠知道的指导下,谢谢。要是有什么原代码就太感谢了。这是我写的一个方法,也找了不少资料,参数是,dataset,要生成的 excel 的路径,根据 strColumnName 这一列的值 生成不同的 excel 文件名称为 1.xls,2.xsl. 希望对你有帮助.要

      5、先添加对 excel 的引用,在引用中的 com 中选 Public Sub CreateExcel(ByVal _strExcelPath As String, ByVal _ExcelDataSet As DataSet, ByVal _strColumnName As String)Dim xlSheet As Excel.WorksheetDim xlBook As Excel.WorkbookDim xlDBTable As Excel.DataTableDim strPath As StringTrydefine an arry list Dim arry As ArrayListarry = New ArrayListDim dr As DataRowDim i As Integer = 0Dim strAll As Stringfirst,get the deffent columns valuethen send the values into a arrylistdefine a dataview in order to sortDim dv As DataView

      6、dv = New DataView(_ExcelDataSet.Tables(0)sort by the columndv.Sort = _strColumnNameDim tmp As StringDim drv As DataRowViewFor Each drv In dvIf tmp drv.Row(_strColumnName) Thentmp = Convert.ToString(drv.Row(_strColumnName)arry.Add(tmp)End IfNextDim k As Integer = 0For k = 0 To arry.Count - 1Dim xlApp As New Excel.ApplicationxlBook = xlApp.Workbooks.AddxlSheet = xlBook.Worksheets(“sheet1“)the files full namestrPath = _strExcelPath 15 using System.IO;16 using System.Data;17 using System.Reflection;

      7、18 using System.Diagnostics;19 using System.Configuration;20 using System.Collections;21 using Excel;22 23 namespace ProtoType24 25 / 26 / 套用模板输出 Excel,生成 xls 文件和 html 文件27 / Author: Liu Wen28 / Date Created: 2006-829 / 30 public class ExportExcel31 32 #region variable member33 protected string templateFile = null;34 protected string excelFile = null;35 protected string htmlFile = null;36 protected object missing = Missing.Value;37 Excel.ApplicationClass app;38 Excel.Workbook book;39 Excel.Works

      8、heet sheet;40 Excel.Range range;41 private DateTime beforeTime; /Excel 启动之前时间42 private DateTime afterTime; /Excel 启动之后时间43 #endregion44 45 / 46 / 构造函数,将一个已有 Excel 工作簿作为模板,并指定输出路径47 / 48 / Excel 模板文件路径 49 / Excel 输出文件路径 50 / Html 输出文件路径 51 public ExportExcel(string templateFile, string excelFile, string htmlFile)52 53 if(templateFile = null)54 throw new Exception(“Excel 模板文件路径不能为空!“);55 56 if(excelFile = null)57 throw new Exception(“Excel 输出文件路径不能为空!“);58 59 if(htmlFile = null)60 throw new Excep

      9、tion(“Html 输出文件路径不能为空!“);61 62 if(!File.Exists(templateFile)63 throw new Exception(“指定路径的 Excel 模板文件不存在!“);64 65 this.templateFile = templateFile;66 this.excelFile = excelFile;67 this.htmlFile = htmlFile;68 69 /创建一个 Application 对象70 beforeTime = DateTime.Now;71 app = new ApplicationClass();72 /app.Visible = true;73 afterTime = DateTime.Now;74 75 /打开模板文件,得到 WorkBook 对象76 try77 78 book = app.Workbooks.Open(templateFile,missing,missing,missing,missing,missing,79 missing,missing,missing,missing,missing,missing,missing,missing,missing);80 81 catch (Exception e)82 83 throw e;84 85 /得到 WorkSheet 对象86 sheet = (Excel.Worksheet)book.Sheets.get_Item(1);87 88 89 / 90 / 将 DataTable 数据导出到 Excel(可动态插入行)91 / 92 /

      《从数据库中导出图片插入到Excel》由会员洪易分享,可在线阅读,更多相关《从数据库中导出图片插入到Excel》请在金锄头文库上搜索。

      点击阅读更多内容
    最新标签
    发车时刻表 长途客运 入党志愿书填写模板精品 庆祝建党101周年多体裁诗歌朗诵素材汇编10篇唯一微庆祝 智能家居系统本科论文 心得感悟 雁楠中学 20230513224122 2022 公安主题党日 部编版四年级第三单元综合性学习课件 机关事务中心2022年全面依法治区工作总结及来年工作安排 入党积极分子自我推荐 世界水日ppt 关于构建更高水平的全民健身公共服务体系的意见 空气单元分析 哈里德课件 2022年乡村振兴驻村工作计划 空气教材分析 五年级下册科学教材分析 退役军人事务局季度工作总结 集装箱房合同 2021年财务报表 2022年继续教育公需课 2022年公需课 2022年日历每月一张 名词性从句在写作中的应用 局域网技术与局域网组建 施工网格 薪资体系 运维实施方案 硫酸安全技术 柔韧训练 既有居住建筑节能改造技术规程 建筑工地疫情防控 大型工程技术风险 磷酸二氢钾 2022年小学三年级语文下册教学总结例文 少儿美术-小花 2022年环保倡议书模板六篇 2022年监理辞职报告精选 2022年畅想未来记叙文精品 企业信息化建设与管理课程实验指导书范本 草房子读后感-第1篇 小数乘整数教学PPT课件人教版五年级数学上册 2022年教师个人工作计划范本-工作计划 国学小名士经典诵读电视大赛观后感诵读经典传承美德 医疗质量管理制度 2 2022年小学体育教师学期工作总结 2022年家长会心得体会集合15篇
    关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
    手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
    ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.