问题描述
PublicClassForm1Dimx1,x2,y(61),i,jAsSingleDimRichTextBox1AsRichTextBoxDimfile=0PrivateSubForm1_Load(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesMyBase.LoadDimnewbookAsExcel.Application'声明对象变量newbook=NewExcel.Application'初始化对象变量newbook.SheetsInNewWorkbook=1'将新建的工作薄数量设为1newbook.Workbooks.Add()'增加一个工作薄newbook.Sheets(newbook.Sheets.Count).Name="基表"'修改工作薄名称newbook.Cells(1,2)="x"newbook.Cells(1,3)="y"Fori=1To61newbook.Cells(i+1,1)=iNextIfDir("c:a.xls")<>""Then'判断该文件是否存在,若存在,则删除该文件Kill("c:a.xls")EndIfnewbook.ActiveWorkbook.SaveAs("c:a.xls")newbook.Quit()newbook=Nothing'清除对象EndSubPrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Clickfile=file+1j=0Fori=x1Tox2Step0.5y(j)=i^2+2*i-2j=j+1Nextj=j-1TextBox3.Text=y(0)TextBox4.Text=y(j)Button2.Enabled=TrueEndSubPrivateSubButton2_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton2.ClickDimExAppAsNewExcel.ApplicationDimExbAsExcel.WorkbookExb=ExApp.Workbooks.Open("c:a.xls")ExApp.Sheets(ExApp.Sheets.Count).Name="sheet1"Dimn,kAsIntegern=0Fori=x1Tox2Step0.5ExApp.Cells(2+n,2)=in=n+1Nextn=0Fork=0TojExApp.Cells(2+n,3)=y(k)n=n+1NextDimSdlgAsSaveFileDialog=NewSaveFileDialog'定义一个保存对话框'Sdlg.FileName="*.xls"'保存对话框的默认文件名Sdlg.InitialDirectory="e:"Sdlg.FileName=CStr(file)&".xls"Sdlg.Filter="EXCEL档案(*.Xls)|*.Xls"'过滤器设置IfSdlg.ShowDialog=Windows.Forms.DialogResult.OKThen'如果保存对话框的确认按钮被按下Exb.SaveAs(Sdlg.FileName)'保存文件EndIfExApp.Workbooks.Close()ExApp.Quit()ExApp=NothingButton3.Enabled=TrueEndSubPrivateSubTextBox2_TextChanged(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesTextBox2.TextChangedx1=Val(TextBox1.Text)x2=Val(TextBox2.Text)Button1.Enabled=TrueEndSubPrivateSubButton3_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton3.ClickDimT,F,K,AT=CreateObject("MSComDlg.CommonDialog")T.DialogTitle="打开一个文件"T.Filter="EXCEL档案(*.Xls)|*.Xls|所有文件|*.*"T.MaxFileSize=260T.flags=4T.action=1IfT.filename<>""ThenK=CreateObject("Scripting.FileSystemObject")A=K.GetFile(T.filename)F=CreateObject("wscript.shell")Err.Clear()F.Run(A.ShortPath,1)EndIfEndSubEndClass以上代码实现了打开并保存数据到excel,请高手帮忙改下,我想实现能存图片到excel的功能,谢谢指点
解决方案
解决方案二:
ActiveSheet.Pictures.Insert(图片文件名).Select
解决方案三:
或者DimpathAsString="D:MyDocumentsMyPictures2.jpg"DimpicAsImagepic=Image.FromFile(path)ExlSheet.Activate()ExlSheet.Shapes.AddPicture(path,Microsoft.Office.Core.MsoTriState.msoCTrue,Microsoft.Office.Core.MsoTriState.msoCTrue,100,100,600,600)
解决方案四:
前一个是Excel得VBA支持得;后一个是Excel对象进行操作得
解决方案五:
图片可以直接复制到剪贴板后直接可以粘贴到EXCEL中的
解决方案六:
参考:
解决方案七:
i=10xlsheet.Cells(i,9).Selectxlsheet.Cells(i,9).HorizontalAlignment=xlCenterxlsheet.Cells(i,9).VerticalAlignment=xlCenterSetp=xlsheet.Pictures.Insert("d:/images/products/b/dd.jpg")
解决方案八:
没有做过保存图片的,学习一下。
解决方案九:
MyExcelSheet.Cells(insert_position_a,insert_position_b).Select()MyExcelSheet.Pictures.insert(symbolPath).Select()
解决方案十:
帮顶